World map

 

BM: Baca dalam Bahasa Melayu

World K5: Lunch Rush

Scale out at lunch rush: HPA

You will learn: how an HPA adds trays when they get busy, and removes them later.

Checked with Kubernetes 1.37 on 31 Oct 2026

The problem

At noon the queue triples. At 3 pm the food court is empty. How many trays do you want?

Pick one answer.

Watch

You are here: cluster kind-dev namespace default
During lunch rush the HPA shop shows cpu 81% against a 50% target and 10 replicas. The shop Deployment is 10/10 ready. Terminal output: $ kubectl get hpa shop NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE shop Deployment/shop cpu: 81%/50% 3 10 10 72s $ kubectl get deployment shop NAME READY UP-TO-DATE AVAILABLE AGE shop 10/10 10 10 72s

A HorizontalPodAutoscaler (HPA): A helper manager who adds trays when they get busy and removes them when it is quiet. (HPA) is a helper manager. It checks every 15 seconds how busy the trays are. Busy? It orders more. Lunch took this shop from 3 to 10.

Predict

“Busy” means CPU use as a share of each tray’s request. The target is 50%. Now 3 trays run at 100%. How many trays does the HPA want?

Pick one answer.

Try it

An HPA is YAML too. This one will not apply. Read kubectl’s error, then fix the one line.

Fix the manifest, then press Apply.

hpa.yaml12 lines

Try it

Now do it with one command. Make the HPA, then press Lunch rush. Watch the trays grow.

kubectl autoscale deployment shop --cpu=50% --min=3 --max=10
You are here: cluster kind-dev namespace default
Stalls: 3. Trays: 3 (3 ready). Waiting for a stall: 0.
  • shop3/3 ready
dev-control-planeOpenManager

No trays here.

dev-workerOpen
  • shop·6l2p4
dev-worker2Open
  • shop·5gkrw
  • shop·nlvkf
Time: +0s (sped up)

Watch

You are here: cluster kind-dev namespace default
An HPA on trays without a CPU request shows cpu: unknown out of 50%. Terminal output: $ kubectl get hpa shop NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE shop Deployment/shop cpu: <unknown>/50% 3 10 3 32s

cpu: <unknown>/50% means: these trays have no CPU request. Without a request, “50% busy” has no meaning. Add resources.requests.cpu to the container.

Predict

Lunch ends. CPU drops to 5%. When do the extra trays go away?

Pick one answer.

You did it!

You can now let an HPA add and remove trays for you.

Go deeper (optional)

Scaling down waits 5 minutes by default. Scaling up may double, or add 4 trays, per 15 seconds. Tune both with behavior in the YAML. In Kubernetes 1.37, minReplicas: 0 (scale to zero) is beta and on by default. It needs an object or external metric, not CPU.

Real rep (optional): try the HPA walkthrough on kubernetes.io. Use a throwaway kind cluster.