Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Horizontal Pod Autoscaler

Direct answer

The Horizontal Pod Autoscaler changes replica counts based on metrics (CPU/memory utilisation vs requests, or custom metrics).

When to use this

Use it to scale workloads with load, or when the HPA does not scale.

First 30 seconds

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.

Operational verification

metrics → HPA compares to target → scales the Deployment

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it to scale workloads with load, or when the HPA does not scale.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

Needs metrics-server (or a metrics adapter) and resource requests. Shows <unknown> when metrics are missing. Set sensible min/max and stabilisation windows.

Key checks
  • kubectl get hpa — first check for this topic
  • kubectl get pods -o wide — pods, status, node, IP
  • kubectl describe pod <pod> — events and conditions
  • kubectl 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'
ConditionMeaning
AbleToScale=FalseCannot read or update the target's scale
ScalingActive=False, FailedGetResourceMetricmetrics-server missing or no requests set
ScalingLimited=True, TooManyReplicasCapped by maxReplicas

Remove replicas from the Deployment manifest when an HPA manages it, or every apply resets the count.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • HPA without resource requests.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

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.

Aliases that resolve here
horizontal pod autoscalerhorizontal pod autoscalermetrics-server
Confirmation

Confirm action

Continue?