Kubernetes · Orchestration under pressure

How does the Horizontal Pod Autoscaler work?

MediumhpaautoscalingmetricsUpdated Oct 2026
Quiz this track

Short answer

HPA adjusts replica counts based on observed metrics versus targets. It needs a metrics source, works best with well-defined requests, and reacts on a delay rather than instantly.

The HPA controller periodically reads metrics and computes a desired replica count. For CPU, the target is a percentage of requests, so missing requests make CPU-based scaling meaningless. HPA can also use memory, custom metrics or external metrics through adapters.

  • metrics-server is enough for CPU and memory, but not for custom metrics
  • Scale-up is usually fast; scale-down is stabilized to avoid flapping
  • HPA scales pods, not nodes; cluster autoscaler or Karpenter handles nodes
  • Metrics must be available for all targeted pods or the calculation is incomplete
  • HPA and a Deployment with a fixed replica count conflict over the same field
yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 3
  maxReplicas: 30
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 65

Autoscaling is only useful if the application scales horizontally and starts fast enough. Cold starts, connection pools and shared caches can make extra replicas ineffective. Tune the stabilization window and scaling policies to match traffic patterns, and test scale-up under realistic load.

A common failure is HPA showing unknown metrics. Check that metrics-server is running, the pods have requests, and the metrics API is reachable from the controller.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does CPU-based HPA require resource requests?
  2. 2What is the difference between HPA and cluster autoscaler?
  3. 3How do you stop HPA from flapping?
  4. 4When would custom metrics be better than CPU?

Say it in the interview

HPA changes replica counts from observed metrics against targets. CPU scaling is based on requests, so missing requests or missing metrics break it. I usually start with CPU and add custom metrics when the real bottleneck is queue depth or latency. I also remember that HPA scales pods only, so node capacity has to come from a cluster autoscaler or Karpenter.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Kubernetes mock interview and get scored feedback on depth, clarity and confidence.