Home > OS >  Custom metrics calculation HPA
Custom metrics calculation HPA

Time:12-04

I was wondering regarding Kubernetes HPA custom metrics HPA how it is calculated with targetAverageValue. If for example I’m using the metric that scales pods based on the number of nginx request then each pod now have is own specific metric and I was wondering if it takes each pod and check regarding its value or if it takes all of their metrics and divide this by the number of the pods?

CodePudding user response:

The Kubernetes Horizontal Pod Autoscaler (HPA) calculates the average value of the metric that you specify as the target value. This means that if you are using a custom metric that scales pods based on the number of nginx requests, the HPA will calculate the average value of that metric across all of the pods in the deployment.

For example, let's say you have a deployment with three pods, and each pod is receiving a different number of nginx requests. The HPA will calculate the average value of the metric across all three pods, and use that value to determine whether to scale the deployment up or down.

Here's an example of how this might work:

Pod 1 receives 10 nginx requests per minute
Pod 2 receives 20 nginx requests per minute
Pod 3 receives 30 nginx requests per minute

The total number of nginx requests for the deployment is 60 (10 20 30). The average value of the metric is 20 (60 / 3), which is the value that the HPA will use to determine whether to scale the deployment up or down.

I hope this helps!

CodePudding user response:

In Kubernetes HPA, the custom metrics calculation is based on the average value of the metric across all pods. So, if you are using a custom metric that scales pods based on the number of nginx requests, the HPA will take the sum of the metrics from all pods and divide it by the total number of pods to calculate the average value of the metric. This average value will then be compared with the targetAverageValue to determine if the number of pods needs to be scaled up or down.

CodePudding user response:

HPA uses the targetAverageValue to determine how to scale the number of pods in a deployment. The HPA calculates the average value of the metric across all pods in the deployment, and compares it to the targetAverageValue. If the average value is greater than the targetAverageValue, the HPA will scale up the number of pods. If the average value is less than the targetAverageValue, the HPA will scale down the number of pods.

For example, if you have a deployment with 10 pods and a targetAverageValue of 50 for the number of nginx requests, the HPA will calculate the average number of nginx requests across all 10 pods. If the average is greater than 50, the HPA will scale up the number of pods to handle the increased load. If the average is less than 50, the HPA will scale down the number of pods to reduce resource usage.

In summary, the HPA calculates the average value of the metric across all pods in the deployment, and uses that value to determine how to scale the number of pods.

Read more: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

  • Related