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

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


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.