Horizontal Pod Autoscaler
In one line
The HPA is a Kubernetes resource that automatically scales the number of Pods in a Deployment based on CPU, memory, or custom metrics.
In simple words
The Horizontal Pod Autoscaler (HPA) is Kubernetes' built-in auto scaler for Pods. "Horizontal" means it scales by adding or removing Pod instances, not by changing the size of existing Pods.
You define an HPA with a target — e.g., "keep CPU usage at 70%". The HPA continuously checks the actual CPU usage. If it is above 70%, it adds more Pods. If it is below 70%, it removes Pods (down to your configured minimum).
The HPA can scale based on CPU, memory, or custom metrics (like requests per second, queue depth). Custom metrics require a custom metrics adapter. The HPA checks metrics every 30 seconds by default and can scale from a minimum to a maximum number of replicas.
Example
# Create an HPA that scales between 2 and 10 Pods
kubectl autoscale deployment my-app --min=2 --max=10 --cpu-percent=70
# Check HPA status
kubectl get hpa my-appThis command creates an HPA for the my-app Deployment, keeping CPU at 70% with 2-10 replicas.
How it works
- The HPA controller reads metrics from the metrics API every 30 seconds.
- It calculates the desired replica count based on the target metric.
- It updates the Deployment's replica count.
- The Deployment creates or removes Pods to match the new count.
Common confusions
Confused with: Vertical Pod Autoscaler
The difference: HPA adds or removes Pods (horizontal scaling); VPA increases or decreases CPU/memory per Pod (vertical scaling). You cannot use both on the same resource for the same metric.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.