Use it to scale workloads with load, or when the HPA does not scale.
Horizontal Pod Autoscaler
The Horizontal Pod Autoscaler changes replica counts based on metrics (CPU/memory utilisation vs requests, or custom metrics).
1. kubectl get hpa — targets and replicas.
2. <unknown> → metrics-server: kubectl top pod.
3. Requests set on containers?
4. kubectl describe hpa — events and conditions.
5. Load test.
metrics → HPA compares to target → scales the Deployment
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Confirm the HPA shows real numbers, not <unknown>. Load-test and watch replicas increase. Check scale-down stabilisation if replicas stay high after load drops.
Step 2 Common failures Narrow the fault
<unknown> targets mean metrics-server is missing or requests are not set. Scaling on CPU does not help a workload limited by a database. A Deployment replicas field managed by GitOps can fight the HPA.
Needs metrics-server (or a metrics adapter) and resource requests. Shows <unknown> when metrics are missing. Set sensible min/max and stabilisation windows.
kubectl get hpa— first check for this topickubectl get pods -o wide— pods, status, node, IPkubectl describe pod <pod>— events and conditionskubectl logs <pod> [-c <c>] [--previous]— container logs (incl. previous crash)kubectl get events --sort-by=.lastTimestamp— recent cluster events
ReferenceWhat it is1 section · depth on demand
How it works
The HPA controller queries the metrics API every 15 seconds, computes desired replicas as current replicas × current value ÷ target value, and applies scaling behaviour rules that limit how fast it scales up and down.
ReferenceImportant terms & boundaries3 sections · depth on demand
HPA example
kubectl autoscale deployment web --cpu-percent=70 --min=2 --max=10
kubectl get hpa ; kubectl describe hpa web
Documented example, not captured output. Needs metrics-server (CPU/memory) or a custom metrics adapter (Prometheus Adapter, KEDA). Pods must have CPU requests, because utilisation is a percentage of the request. <unknown> targets mean metrics are missing.
In depth
The scaling formula
desiredReplicas = ceil(currentReplicas × currentMetric / targetMetric)
Example: 4 replicas at 90 % average CPU utilisation with a 60 % target → ceil(4 × 90 / 60) = 6. Utilisation is measured against the container's CPU request, so Pods without requests cannot be scaled on utilisation. No change is made while the ratio is within a 10 % tolerance.
autoscaling/v2 example with behaviour
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata: { name: web }
spec:
scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: web }
minReplicas: 2
maxReplicas: 20
metrics:
- type: Resource
resource: { name: cpu, target: { type: Utilization, averageUtilization: 60 } }
behavior:
scaleDown:
stabilizationWindowSeconds: 300 # default; avoids flapping
policies: [{ type: Percent, value: 50, periodSeconds: 60 }]
Reading HPA status
kubectl get hpa web
# TARGETS cpu: 92%/60% REPLICAS 4 → 7
kubectl describe hpa web | sed -n '/Conditions/,$p'
| Condition | Meaning |
|---|---|
AbleToScale=False | Cannot read or update the target's scale |
ScalingActive=False, FailedGetResourceMetric | metrics-server missing or no requests set |
ScalingLimited=True, TooManyReplicas | Capped by maxReplicas |
Remove replicas from the Deployment manifest when an HPA manages it, or every apply resets the count.
Common mistakes
- HPA without resource requests.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.