0
0
Kubernetesdevops~10 mins

Horizontal Pod Autoscaler in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Horizontal Pod Autoscaler
Monitor Metrics
Compare Current Load with Target
Decide to Scale Up or Down
Increase
Change Pod Count
Wait & Repeat
The Horizontal Pod Autoscaler watches metrics, compares them to targets, then adjusts pod count up or down accordingly, repeating continuously.
Execution Sample
Kubernetes
kubectl autoscale deployment myapp --min=2 --max=5 --cpu-percent=50
This command creates an autoscaler for 'myapp' deployment to keep CPU usage near 50%, scaling pods between 2 and 5.
Process Table
StepCurrent CPU %Target CPU %Pods BeforeDecisionPods After
130502CPU below target, no scale change2
255502CPU above target, scale up3
370503CPU well above target, scale up4
445504CPU below target, scale down3
520503CPU well below target, scale down2
650502CPU at target, no change2
💡 Autoscaler continuously monitors; this trace shows decisions over 6 checks.
Status Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6
Current CPU %N/A305570452050
Pods Count2234322
Key Moments - 3 Insights
Why doesn't the pod count change when CPU is below target but not very low (Step 1)?
At Step 1, CPU is 30%, below the 50% target but not low enough to trigger scaling down, so pods remain at 2 as shown in execution_table row 1.
Why does the pod count increase by only one pod at each scale-up step?
The autoscaler adjusts pods gradually to avoid sudden changes; at Steps 2 and 3, it increases pods by one each time, as seen in execution_table rows 2 and 3.
Can the pod count go below the minimum set (2 pods)?
No, the autoscaler respects the minimum pods limit; even when CPU is very low at Step 5, pods do not go below 2, as shown in execution_table row 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the pod count after Step 3?
A4
B3
C2
D5
💡 Hint
Check the 'Pods After' column in row for Step 3.
At which step does the autoscaler decide to scale down the pods for the first time?
AStep 2
BStep 4
CStep 1
DStep 5
💡 Hint
Look for the first 'scale down' decision in the 'Decision' column.
If the CPU target was changed to 60%, how would the decision at Step 2 change?
AStill scale up
BScale down
CNo scale change
DScale up by 2 pods
💡 Hint
Compare current CPU (55%) with new target (60%) in Step 2 row.
Concept Snapshot
Horizontal Pod Autoscaler (HPA):
- Monitors pod metrics (e.g., CPU usage).
- Compares current metric to target.
- Scales pod count up/down within min/max limits.
- Runs continuously to keep app responsive.
- Command example: kubectl autoscale deployment NAME --min=X --max=Y --cpu-percent=Z
Full Transcript
The Horizontal Pod Autoscaler watches the CPU usage of pods in a deployment. It compares the current CPU percentage to a target value. If the CPU is higher than the target, it increases the number of pods by one to handle more load. If the CPU is lower than the target, it decreases the number of pods by one to save resources, but never below the minimum set. This process repeats continuously to keep the application running efficiently. The example command sets up autoscaling for a deployment named 'myapp' with a minimum of 2 pods, maximum of 5 pods, and a target CPU usage of 50%. The execution table shows how the pod count changes step-by-step based on CPU usage readings.