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

Four-panel comic about Horizontal Pod Autoscaler: Traffic doubles at lunch. Four checkout pods run hot at 90% CPU and Asha watches latency climb; The HPA checks every 15 seconds: desired = ceil(current x actual / target); ceil(4 x 90 / 60) = 6. Two new pods start and CPU settles near 60%;...