Using them both at the same time is not suggested because if they both detect that the memory is need they might want to try to resolve the same problems at the same time which will lead to wrongly allocated resources.
This is not something that can be specified at the application deployment level but you can specify which deployment should HPA
and VPA
scale using targetRef
So for the deployment with app1
you can specify VPA
:
apiVersion: autoscaling.k8s.io/v1beta2
kind: VerticalPodAutoscaler
metadata:
name: app1-vpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: app1
And for the app2
you can specify to use HPA
:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: app2-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: app2
If need to use HPA and VPA together on the same deployments, you just have to make sure that the will based they behavior on different metrics. This way you prevent them by being scaled by the same event. To summarize VPA and HPA can be used together if he HPA config won`t use CPU or Memory to determine its targets as stated in the documentation:
"Vertical Pod Autoscaler should not be used with the Horizontal
Pod Autoscaler (HPA) on CPU or memory at this moment"