100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
DevOps

Horizontal Pod Autoscaler

Kubernetes pod-count autoscaling controller

IntermediateTool10K learners

The Horizontal Pod Autoscaler (HPA) is a Kubernetes controller that automatically adjusts the number of pod replicas in a Deployment or StatefulSet based on observed metrics like CPU utilization, memory usage, or custom application metrics.

Definition

The Horizontal Pod Autoscaler (HPA) is a Kubernetes controller that automatically adjusts the number of pod replicas in a Deployment or StatefulSet based on observed metrics like CPU utilization, memory usage, or custom application metrics.

Overview

The Horizontal Pod Autoscaler continuously watches metrics for a target workload and compares them against a configured threshold, adding or removing pod replicas to keep the observed metric near the target. In its most common configuration, an HPA targets average CPU utilization across a Deployment's pods — for example, keeping average CPU near 50% — scaling out by adding replicas when traffic spikes push utilization higher, and scaling back in when demand drops. Beyond CPU and memory, which come from the Kubernetes metrics server by default, the HPA can scale on custom or external metrics through the custom metrics API, enabling scaling decisions based on application-specific signals such as queue depth, requests per second, or latency, sourced from monitoring systems like Prometheus via an adapter. This flexibility lets teams scale based on the metric that actually reflects load for their application, rather than being limited to CPU alone, which can be a poor proxy for load in I/O-bound or queue-based services. HPA works purely at the pod-replica level — it changes how many copies of a pod are running, not how much CPU or memory each individual pod is allocated, which is the job of the complementary Vertical Pod Autoscaler. It also depends on the underlying cluster having enough node capacity to schedule new pods; if the cluster doesn't have room, the Cluster Autoscaler typically works alongside the HPA, adding nodes so the newly requested pods can actually be scheduled. A well-tuned HPA configuration also considers stabilization windows and scale-up/scale-down policies, which control how aggressively the controller reacts to metric changes, preventing rapid flapping between scaling up and down in response to noisy or spiky metrics.

Key Features

  • Automatically adjusts pod replica count based on observed metrics
  • Commonly scales on CPU or memory utilization by default
  • Supports custom and external metrics via adapters like Prometheus
  • Works at the replica-count level, distinct from Vertical Pod Autoscaler
  • Requires sufficient node capacity, often paired with Cluster Autoscaler
  • Configurable stabilization windows to prevent scaling flapping
  • Built into core Kubernetes as a native autoscaling controller

Use Cases

Scaling a web service's pod count with incoming traffic
Scaling workers based on message queue depth
Handling traffic spikes automatically without manual intervention
Reducing pod count and cost during low-traffic periods
Scaling on custom application metrics like requests per second

Frequently Asked Questions