Services

Resources

Company

HPA (Horizontal Pod Autoscaler)

A Horizontal Pod Autoscaler (HPA) is a Kubernetes controller that changes the number of pod replicas in a Deployment or StatefulSet based on a metric. You set a target, such as 60% average CPU utilization, and the HPA adds pods when load rises and removes them when it falls. It scales out, not up.

How it works

Every 15 seconds by default, the controller reads the metric and computes desiredReplicas = ceil(currentReplicas x currentValue / targetValue). With 4 pods at 90% CPU and a 60% target, it asks for ceil(4 x 90 / 60) = 6 pods. CPU utilization is measured against each pod's resource request, so pods without requests cannot scale on CPU. Scale down waits through a 5 minute stabilization window by default to avoid flapping. Custom and external metrics, such as queue depth, work through a metrics adapter.

Why it matters in production

The HPA turns traffic peaks into extra replicas without a human in the loop. It only works if new pods start fast and the cluster has room for them, so it is usually paired with a cluster autoscaler. Wrong requests or a slow image make it react late.

See also

On the One2N blog

Further reading

Comic about the Horizontal Pod Autoscaler: visitors rush a shop site and its 4 pods run 90% busy with slow pages; to keep each about 60% busy, 4 x 90% is 360 of work, and 360 / 60 means 6 pods, a sum Kubernetes does every 15 seconds; it starts 2 more pods and all 6 sit at 60% with fast pages; when the rush ends it goes back to 4 after a short wait.