Hands-on Lab·Certified Kubernetes Administrator
HorizontalPodAutoscaler
Put real load on a Deployment and watch it go from one replica to six. The target is a percentage of the CPU request, not of the node, so a Pod with no request can never be autoscaled at all.
Workloads Guide 33 of 103 Intermediate
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 35 min
Needs metrics-server. Without it the HPA reports FailedGetResourceMetric and never scales.
- APIautoscaling/v2
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when load varies and the replica count should follow it. This matters because an HPA computes a percentage of the CPU request rather than of the node, and its scale-down is deliberately slow - both of which surprise people watching one for the first time.
- creating an HPA with
kubectl autoscale, and noting the flag it warns is on its way out - reading back the API version the object was actually stored as
- seeing the error it reports for the first minute, before any metrics have arrived
- putting real load on with a tight request loop and watching replicas climb
- removing the load and finding scale-down deliberately slow, governed by a stabilisation window
Before you start
- The metrics-server guide. The HPA reads the same Metrics API
kubectl topdoes. - The requests, limits and QoS guide, because the target is a percentage of the request.
- The Deployments guide.
-
Create it, and note the flag that is on its way out
-
Idle, and the error you see for the first minute
-
Real load, and the scale-up
-
Remove the load: scale-down is deliberately slow