Lab 6: Autoscaling Under Load
This is the answer to “how do we scale?”, running live.
Setup: three windows
Section titled “Setup: three windows”# terminal 1kubectl get hpa -n demo --watch# terminal 2make watch# browserhttp://localhost:8080Check that metrics work: kubectl top pods -n demo should show numbers. If it says metrics not available, wait a minute after make up.
Generate load
Section titled “Generate load”make load-onThis starts a busybox pod inside the cluster that calls http://demo/api/burn?ms=200 in 4 parallel loops. Each call burns 200 ms of CPU.
What you’ll see (about 1–3 minutes)
Section titled “What you’ll see (about 1–3 minutes)”NAME REFERENCE TARGETS MINPODS MAXPODS REPLICASdemo Deployment/demo cpu: 3%/50% 2 10 3demo Deployment/demo cpu: 379%/50% 2 10 3 ← load hitsdemo Deployment/demo cpu: 254%/50% 2 10 10 ← ceil(3 × 379/50) = 23, capped at max 10demo Deployment/demo cpu: 188%/50% 2 10 10(Real output from building this lab.) New pods appear, warm up, join the Service, and the visualizer fills up with cards. CPU per pod drops as the work is shared.
kubectl describe hpa demo -n demo | tail -8 # "New size: 10; reason: cpu resource utilization above target"kubectl top pods -n demoRemove load
Section titled “Remove load”make load-offAfter the 30s stabilization window (300s by default in real clusters), the HPA scales back down to minReplicas: 2. Scaling down is deliberately slower than scaling up.
Browser load
Section titled “Browser load”The Browser CPU load button sends burn requests from your browser. Browsers cap parallel connections, so it’s gentler. Try it with minReplicas and watch the HPA react a little.
Experiments
Section titled “Experiments”- Change
averageUtilizationto20and re-apply. Does it scale higher? - Lower the CPU limit to
200min the Deployment. Pods get throttled, so requests get slower. - Set
minReplicas: 1. What happens to availability duringmake chaos?