autoscaler icon indicating copy to clipboard operation
autoscaler copied to clipboard

Can the VPA and HPA be used together on separate resource metrics?

Open dippynark opened this issue 2 years ago • 1 comments

I have found similar questions and answers in other issues and in the multidimensional autoscaler AEP however I am still unsure on the answer.

The VPA limitations state the following:

Vertical Pod Autoscaler should not be used with the Horizontal Pod Autoscaler (HPA) on CPU or memory at this moment. However, you can use VPA with HPA on custom and external metrics.

This sounds to me like you cannot use VPA and HPA together on separate resource metrics, however I do not see why you couldn't use VPA to vertically scale only on memory and use HPA to horizontally scale only on CPU (as done by Google's MultidimPodAutoscaler). The multidimensional autoscaler AEP does state that for some applications this can lead to memory being scaled down as the number of replicas are scaled up, however this sounds like expected (and desired) behaviour and not something that would prevent VPA and HPA being used together.

From my limited testing, this seems to work great for Nginx Ingress Controller:

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ingress-nginx-controller
  updatePolicy:
    updateMode: Auto
  resourcePolicy:
    containerPolicies:
    - containerName: controller
      controlledResources:
      - memory
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ingress-nginx-controller
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80

The multidimensional autoscaler AEP describes why you cannot use VPA and HPA on the same resource metric and I can also see why the multidimensional autoscaler would provide more value than combining VPA and HPA (since it might be useful to vertically scale on CPU too), however until that is ready combining VPA and HPA on separate resource metrics is still very powerful.

If this is possible and there are not any known edge cases when doing this, I would be happy to create a PR to clarify this in the VPA limitations.

dippynark avatar Nov 05 '23 23:11 dippynark

If this is possible and there are not any known edge cases when doing this, I would be happy to create a PR to clarify this in the VPA limitations.

Thanks for offering to create a clarifying PR! I think we'd be happy to merge this in. Great investigation work on the Google Multi-dimensional PodAutoscaler!

voelzmo avatar Dec 07 '23 09:12 voelzmo

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Mar 06 '24 09:03 k8s-triage-robot

/remove-lifecycle stale /lifecycle frozen /label help-wanted

voelzmo avatar Mar 06 '24 13:03 voelzmo

@voelzmo: The label(s) /label help-wanted cannot be applied. These labels are supported: api-review, tide/merge-method-merge, tide/merge-method-rebase, tide/merge-method-squash, team/katacoda, refactor. Is this label configured under labels -> additional_labels or labels -> restricted_labels in plugin.yaml?

In response to this:

/remove-lifecycle stale /lifecycle frozen /label help-wanted

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 06 '24 13:03 k8s-ci-robot

@voelzmo ah sorry for the delay on this, will try to create a PR before the end of the week

dippynark avatar Mar 06 '24 18:03 dippynark

@dippynark awesome, thanks!

voelzmo avatar Mar 07 '24 08:03 voelzmo

/triage accepted

Shubham82 avatar Mar 13 '24 09:03 Shubham82