3

I am new to kubernetes and HPA. I did not find both the CPU and memory target thresholds configuration together in the official docs Is it possible to do something like below?

My current sample hpa spec:-

hpaSpec:
        maxReplicas: 10
        minReplicas: 5
        targetCPUUtilizationPercentage: 50
        targetMemoryUtilizationPercentage: 80

Does this mean that the pods will scale up in both the following conditions:-

  1. CPU utilization > 50% even if memory utilization <80%    
  2. memory utilization > 80% even if CPU utilization <50% 

OR

 1. If both CPU utilization > 50%  and memory utilization >80% 

Similarly, will it scale down if either CPU utilization falls below 50% or memory utilization falls below 80% or only if both threshold conditions are satisfied? (Is it an OR or AND condition on the thresholds?)

Is there a better way do this i.e. use averageUtilization instead? TIA

sparkstar
  • 131
  • 1
  • 3

1 Answers1

1

In the Horizontal Pod Autoscaler docs, Algorithm Details section, you can read:

If multiple metrics are specified in a HorizontalPodAutoscaler, this calculation is done for each metric, and then the largest of the desired replica counts is chosen. If any of these metrics cannot be converted into a desired replica count (e.g. due to an error fetching the metrics from the metrics APIs) and a scale down is suggested by the metrics which can be fetched, scaling is skipped. This means that the HPA is still capable of scaling up if one or more metrics give a desiredReplicas greater than the current value.

That means, if one of the metrics meets the threshold, the deployment will be scaled up.
Same goes for the scale down.

p10l
  • 386
  • 1
  • 7
  • Hello @sparkstar and welcome to ServerFault! Please remember to [react to answers for your questions](https://stackoverflow.com/help/someone-answers). That way we know if the answers were helpful and other community members could also benefit from them. Try to [accept answer](https://stackoverflow.com/help/accepted-answer) that is the final solution for your issue, upvote answers that are helpful and comment on those which could be improved or require additional attention. Enjoy your stay! – Wytrzymały Wiktor Aug 26 '21 at 08:24