How does the Horizontal Pod Autoscaler work?medium

Type
conceptual
Topic
scaling
Frequency
common
Tags
scaling
Answer

HPA watches a metric (CPU, memory, or custom) and adjusts the replica count of a Deployment to keep the metric near a target value - scaling out under load and in when idle.

Explanation

HPA computes: desired_replicas = current_replicas × (current_metric / target_metric) . CPU autoscaling requires resource requests set on containers - without them, HPA cannot calculate utilization. Custom metrics (queue depth, request rate) are available via the Custom Metrics API (Prometheus Adapter, KEDA). Scale-down is intentionally slower than scale-up to avoid oscillation. Set min and max replicas to bound the behavior.

Follow-upWhat is KEDA and how does it extend autoscaling beyond CPU?