How does the Kubernetes Horizontal Pod Autoscaler (HPA) work?
⚡
Quick Answer
The HPA automatically adjusts a workload replica count based on observed metrics (CPU, memory, or custom/external metrics), scaling out under load and back in when demand drops.
Detailed Answer
A control loop periodically compares a metric against a target (e.g., 60% CPU) and computes the desired replicas, respecting min/max bounds and stabilization windows to avoid flapping. It relies on the metrics-server (or an adapter for custom metrics). Because the HPA owns replicas, do not also pin replicas in your manifest or the two will fight.
💡
Interview Tip
The pro insight: the HPA owns spec.replicas, so remove replicas from your Deployment manifest to avoid conflicts.
kuberneteshpaautoscaling