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.
Horizontal replica demand
- HPAPending Podsmore replicas
HPA can create more desired Pods, but placement may fail if the existing workers lack room.
Vertical request sizing
- VPAPending Podsper-Pod size
- VPAHPAdenominator interaction
VPA changes or recommends requests. Those requests affect fit and can change CPU-utilization denominators used by HPA.
Eligible node capacity
- Pending PodsNode autoscalerunschedulable demand
- Node autoscalerNew workercreate suitable node
An installed node autoscaler evaluates whether provider capacity can satisfy the unschedulable Pods within configured limits.
Wait for the new capacity to serve
- New workerReady applicationplace and start
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.
Explore another case
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: 300How 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.
- Metrics pipelineReport observed CPU usageHPA controllerThe controller relates usage to requested CPU.
- HPA controllerCompare utilization with the targetReplica recommendationA high reading can recommend more replicas, within configured bounds and policies.
- HPA controllerUpdate the scale targetDeploymentThe Deployment begins adding the requested Pods.
- New PodsReport readinessService endpointsAdditional usable capacity appears after startup.
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.
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.
- Before
- 60% observed / 60% target
- After
- 20% observed / 60% target
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.
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 replicasInspect YAML or commands
Compute the simple ratio
kubectl get hpa api -o yamlVerify useful capacity
kubectl get hpa
kubectl get pods -l app=apiExplore 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.creationTimestampIn 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