Horizontal Pod Autoscaler
The Horizontal Pod Autoscaler automatically adjusts the number of pod replicas based on CPU, memory, or custom metrics to match demand.
The Horizontal Pod Autoscaler (HPA) is a Kubernetes controller that automatically scales the number of pod replicas in a workload up or down to match demand. It implements horizontal scaling, adding or removing pods, rather than vertical scaling, which resizes a single pod.
How It Works
The HPA targets a scalable workload such as a Deployment, ReplicaSet, or StatefulSet. It periodically reads metrics, most commonly average CPU utilization, but also memory, custom application metrics, or external metrics, and compares them against a target value you configure.
Using a ratio of current to desired metric value, the HPA computes the needed replica count and updates the workload, staying within configured minimum and maximum bounds. Stabilization windows and scaling policies dampen rapid fluctuations to avoid thrashing. Metrics are supplied by a metrics pipeline such as the metrics server or a custom metrics adapter.
Why It Matters
Autoscaling matches capacity to load automatically, improving resilience during traffic spikes and reducing cost during quiet periods. It removes the need to manually guess and adjust replica counts, which is error-prone and slow.
The HPA addresses application replicas, not cluster capacity; when there are not enough nodes to schedule new pods, it is paired with a cluster autoscaler. For right-sizing individual pods, a Vertical Pod Autoscaler is used instead.
Related Terms
The HPA scales the pods managed by a Deployment or ReplicaSet, runs as a controller on the control plane, and complements cluster-level autoscaling.