Does HPA(Horizontal pod autoscaling) considers the mean of CPU utilization of multiple containers(in a pod) to scale the pods?

4.9k views Asked by At

I would like to know, if HPA considers the mean of CPU utilization of multiple containers in a pod, in order to scale up/down the no. of pods. For instance, if I specify a HPA like below for a deployment(pod) that has 2 containers. In order for the HPA to scale up, does it require the CPU utilization to be reached to 80% in both the containers? In other words, If container A has CPU utilization of 80% but container B has CPU utilization of only 60%. Does that mean that the pods will not be scaled up by HPA. As far as I have observed, this is the case. But I am not sure about this, since there is no explicit statement regarding this in the kubernetes documentation. And unfortunately, I am not the best of developers to figure this out from the source code. Any help & if possible with reference, would be greatly appreciated. Thank you so much.

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: blackbox-rc-hpa
  namespace: monitoring
spec:
  scaleTargetRef:
    apiVersion: v1
    kind: extensions/v1beta1
    name: blackbox
  minReplicas: 1
  maxReplicas: 4
  targetCPUUtilizationPercentage: 80
3

There are 3 answers

0
Innocent Anigbo On BEST ANSWER

The controller calculates the utilization value as a percentage on the containers in each pod and then takes the mean. So in your scenerio mean will be 70% https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

0
rrh On

The pod resources requested is the sum of the resources requested by all it's containers. So, in that scenario you probably have 70% CPU utilization.

0
Haoyuan Ge On

There is a 10% tolerance of targetCPUUtilizationPercentage. In your case, the average cpu utilization should be larger than 88% to trigger scaling up, and less than 72% to scale down. Because the average CPU utlization is 70%, your replicas will be scaled down to 1.

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details