Score:3

In kubernetes HPA if the configuration has both targetCPUUtilizationPercentage and targetMemoryUtilizationPercentage which is given priority?

gb flag

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

Score:1
us flag

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.

Wytrzymały Wiktor avatar
it flag
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!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.