Appearance

HPA, VPA, and node autoscaling

Diagnose whether scaling needs more Pods, different resource requests, or more node capacity.

What you will understand

  • Calculate a CPU utilization signal using usage and the requested CPU.
  • Explain which resource each type of autoscaler can change.
  • Use metrics, controller conditions, and Pod events to find where scaling is blocked.

Builds on: Kustomize and Helm

Choose what needs to scale

Traffic doubles and the API gets slower. You could run more copies, give each copy more CPU, or add nodes on which to run copies. Kubernetes has different mechanisms for those decisions. The Horizontal Pod Autoscaler (HPA) updates the desired replica count of a scalable workload based on metrics. It needs a working metrics API and application replicas that can share the load.

A Vertical Pod Autoscaler (VPA) is an add-on that recommends requests based on observed usage. Its configured mode determines whether it only recommends or also changes what Pods request. Applying a change may involve in-place updates or Pod replacement, depending on the mode and support. A node autoscaler adds or removes capacity using provider-specific mechanisms. It can add nodes when pending Pods could fit on one that it is allowed to provision. Follow how these decisions interact in the capacity scene.

Choose the capacity change you actually need

HPA can change replica count, VPA can recommend or modify requests, and node autoscaling supplies infrastructure for eligible Pods.

  1. Horizontal replica demand

    HPA can create more desired Pods, but placement may fail if the existing workers lack room.

  2. Vertical request sizing

    VPA changes or recommends requests. Those requests affect fit and can change CPU-utilization denominators used by HPA.

  3. Eligible node capacity

    An installed node autoscaler evaluates whether provider capacity can satisfy the unschedulable Pods within configured limits.

  4. Wait for the new capacity to serve

    The new node and its network/storage agents must work, then Pods must start and pass readiness before demand is actually served.

Optional VPA and node autoscaler are installed in this scenario; a plain local cluster need not have either.

Calculate CPU utilization from requests

Save the HPA as api-hpa.yaml in the example environment. It targets the api Deployment in the same namespace. Each relevant container needs a CPU request for CPU utilization to be calculated. If a replica uses 120m against a request of 200m, it is at 60% utilization. If the same usage has a request of 400m, it reads as 30%. The denominator matters when deciding whether the current replicas appear busy. The HPA also honors the configured bounds of two and eight copies, with a five-minute scale-down stabilization window.

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 2
  maxReplicas: 8
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 60
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300

How does CPU use turn into more replicas?

The HPA compares utilization with a target and updates desired scale. Readiness indicates when those replicas are useful.

  1. Metrics pipelineReport observed CPU usage
    HPA controllerThe controller relates usage to requested CPU.
  2. HPA controllerCompare utilization with the target
    Replica recommendationA high reading can recommend more replicas, within configured bounds and policies.
  3. HPA controllerUpdate the scale target
    DeploymentThe Deployment begins adding the requested Pods.
  4. New PodsReport readiness
    Service endpointsAdditional usable capacity appears after startup.
Follow the sequence

The HPA compares utilization with a target and updates desired scale. Readiness indicates when those replicas are useful.

Simple homogeneous-Pod CPU example; real HPA includes tolerance, missing-metric and readiness handling.

Inspect the scale-down decision

Traffic has dropped and the HPA has fresh metrics, but the Deployment still wants six replicas. Follow the latest calculation and the recent recommendation that keeps the count up.

1 / 5

From Resource metricsTo HPA controller

Observe lower CPU usage

The busy period left a recent recommendation of six replicas. The six replicas are now ready and traffic has fallen. In this example, each now uses 40m against a request of 200m.

Latest utilization and configured target
Before
60% observed / 60% target
After
20% observed / 60% target
Observe lower CPU usage

The busy period left a recent recommendation of six replicas. The six replicas are now ready and traffic has fallen. In this example, each now uses 40m against a request of 200m.

Illustrative CPU values and compressed time. All Pods are ready and have complete metrics and equal requests. The lesson configures a 300-second scale-down stabilization window. This example assumes scale-down rate policies permit the final change.

If CPU has been below target for one minute, does a five-minute stabilization window have to allow scale-down yet?
Reveal prediction answer

A higher recommendation can still be inside the window. The controller considers the recent recommendation history when deciding how far to scale down.

With a working Metrics API, watch the current CPU metric, the HPA’s desired count, and the Deployment’s actual count as load falls.

Compare HPA conditions and Deployment replicas
Inspect YAML or commands

Compute the simple ratio

kubectl get hpa api -o yaml

Verify useful capacity

kubectl get hpa
kubectl get pods -l app=api
Explore another case

Open Inspect the scale-down decision to see why the HPA can keep six replicas after CPU usage falls. The current sample produces a lower recommendation, but the controller considers the highest recommendation still inside the scale-down stabilization window.

Follow a scale-up through readiness

Check resource metrics before generating traffic. Then watch the HPA’s metric, desired count, and conditions. Compare them with the Deployment’s actual and ready replicas. If the HPA wants six copies but two Pods are pending, their events might reveal a placement constraint or insufficient requested CPU. Adding enough suitable nodes can help the latter case. A conflict in required labels or affinities can make new capacity irrelevant.

kubectl top pods -n learning
kubectl apply -n learning -f api-hpa.yaml
kubectl get hpa api -n learning -w
kubectl describe hpa api -n learning
kubectl get deployment api -n learning
kubectl get pods -n learning -l app=api -o wide
kubectl get events -n learning --sort-by=.metadata.creationTimestamp

In the application delivery lab, the baseline lets you inspect the HPA and its conditions. It does not install the Metrics API. A working CPU-based scaling experiment needs that pipeline, a resource request, and sustained traffic you can observe.

When metrics are available, try reducing load once the replicas are ready. Compare the current CPU metric with the desired replica count. If a higher recommendation is still in the window, kubectl describe hpa can report ScaleDownStabilized under AbleToScale.

Check whether the new Pods can help

An HPA reading CPU as a percentage of requests can react to VPA changes even when actual requests per second stay flat. Review the metrics and control policies before enabling both on the same workload. Adding nodes also leaves problems such as slow startup or an unavailable dependency untouched. Inspect where new copies stop becoming usable.

Check your understanding

The HPA wants eight replicas, but only five are ready. The other three have FailedScheduling events. Which component made progress and which decision is blocked?

The HPA calculated a higher desired count. The scheduler has not found eligible nodes for the remaining copies. Read the scheduling events to see whether providing capacity with the right labels and limits can unblock them.

Primary documentation

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