What Kubernetes uses to calculate the CPU ratio, request or limit?

12/3/2019

When you specify and Horizontal Pod Autoscaler in Kubernetes for example with targetCPUUtilizationPercentage of 50, what does Kubernetes use to calculate the CPU ratio, the request or the limit of the container?

So for example, with a request=250 and limit=500 and you want to scale up when is half its limit:

  • If it used the request, I would put the target to 100% at least as it can raise to 200%.
  • If it used the limit, I would use target = 50% as 100% would mean the limit is reached.
-- PhoneixS
autoscaling
kubernetes
kubernetes-pod

1 Answer

12/3/2019

targetCPUUtilizationPercentage of 50 means that if average CPU utilization across all Pods goes up above 50% then HPA would scale up the deployment and if the average CPU utilization across all Pods goes below 50% then HPA would scale down the deployment if the number of replicas are more than 1

I just checked the code and found that targetUtilization percentage calculation uses resource request. refer below code

currentUtilization = int32((metricsTotal * 100) / requestsTotal)

here is the link https://github.com/kubernetes/kubernetes/blob/v1.9.0/pkg/controller/podautoscaler/metrics/utilization.go#L49

-- P Ekambaram
Source: StackOverflow