Appearance

Autoscaling mechanics and feedback

Calculate a first autoscaling recommendation and identify the delays before users see extra capacity.

What you will understand

  • Estimate an HPA replica recommendation from measured and target utilization.
  • Explain how missing metrics, readiness, stabilization, and scaling policies affect the result.
  • Diagnose one slow stage between increased demand and ready Pods.

Builds on: CPU throttling, OOM, and eviction

Calculate the first replica recommendation

An API runs four replicas. Each requests 200m of CPU and uses about 150m during a spike. Its average utilization is 75%, and its HPA target is 50%. The basic recommendation is the current count times observed divided by target, rounded up. Here that gives ceil(4 × 75 / 50) = 6. The scene lets you change usage and requests separately to see which number drives the recommendation.

The Horizontal Pod Autoscaler reads metrics periodically and writes a desired scale when the recommendation passes its rules. CPU utilization is measured relative to requested CPU. If the requests double while actual usage stays the same, utilization falls. A workload with missing CPU requests or an unavailable Metrics API may provide no usable utilization signal for that metric.

How does the HPA estimate a replica count?

Divide average usage by requested CPU to get utilization, compare it with the target, and round the base replica recommendation up.

Current replicas
4
CPU utilization
75%150m used ÷ 200m requested
Target utilization
50%
ceil(4 × 75% ÷ 50%) = 6 replicas

Base recommendation only. The HPA can also apply tolerance, bounds, stabilization, and rate limits.

The arithmetic assumes identical complete ready-Pod observations; real HPA processing adds conservative adjustments and policies.

Explore another case

How HPA rules change the recommendation

The formula is the starting point. The HPA uses a tolerance around the target, handles missing metrics conservatively, and treats not-yet-ready Pods specially when evaluating CPU. If you use multiple metrics, the controller computes recommendations for them and generally chooses the largest valid one. Metric errors can prevent a scale-down even if another metric suggests one. Scaling policies limit changes over time, and a stabilization window can keep a recent higher recommendation during scale-down.

In the example, the replica bounds are two and eight and scale-down looks back five minutes. A short drop in demand can leave the count high while the window still contains a recent larger recommendation.

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: m17-web
  namespace: kv-lab
  labels:
    lab: m17
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: m17-web
  minReplicas: 2
  maxReplicas: 8
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50 # Percent of requested CPU, not CPU limit.
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300

Follow scale-up from demand to readiness

Estimate a desired count before changing requests or load. Check the metrics API, the HPA target and conditions, then the Deployment and ready Pods. Newly created Pods still need placement, image pulls, and readiness. If capacity must grow, an infrastructure autoscaler may need time to add suitable nodes. In the scene, follow the demand spike all the way to the point when new Pods can serve requests.

How long until a scale decision changes usable capacity?

An HPA recommendation is bounded by its rules. The extra Pods still have to be admitted, placed, started, and readied.

  1. HPA controllerApply scaling bounds and behavior
    Deployment scale targetThe accepted desired count increases.
  2. Deployment and ReplicaSet controllersRequest additional Pods
    Scheduler and kubeletsNew copies need placement and startup capacity.
  3. Ready PodsJoin the eligible endpoint set
    Client requestsTraffic can use the new capacity when forwarding catches up.
Follow the sequence

An HPA recommendation is bounded by its rules. The extra Pods still have to be admitted, placed, started, and readied.

Node autoscaling is a separate optional mechanism; its timing and supported capacity depend on the provider.

Explore another case
kubectl --context kind-kv-lab get apiservice v1beta1.metrics.k8s.io
kubectl --context kind-kv-lab -n kv-lab get hpa
kubectl --context kind-kv-lab -n kv-lab describe hpa m17-web
kubectl --context kind-kv-lab -n kv-lab get pods -o wide
# top requires a functioning resource metrics pipeline.
kubectl --context kind-kv-lab -n kv-lab top pods

The performance lab uses HPA status and failure conditions in the local baseline. Live usage and a scale-up experiment require a working resource metrics pipeline and sustained test load.

See how load affects shared dependencies

Extra replicas can increase connections and contention on a shared dependency. Use a metric that reflects what you want to improve. Queue depth can help a worker fleet when work is divisible, while CPU may tell you little about a workload blocked on a saturated database. Measure the end result, such as queue age or request latency.

Check your understanding

The formula predicts six replicas. The HPA reports six desired, but request latency stays high. What are two next checks?

Check whether all six replicas are ready and eligible for traffic. If they are, measure where requests spend time and whether a shared dependency has become the limiting resource.

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu