Scaling
Hub › Kubernetes › 06
Goal
Scale the web Deployment from 1 replica to 4 and back to 2 to see how Kubernetes distributes pods across the cluster.
Why
One replica is a single point of failure. If that pod crashes or its node becomes unavailable, the app is down until the pod is rescheduled. Scaling to multiple replicas means the Service load-balances across healthy pods and Kubernetes can reschedule if a node fails.
Step 1 — Scale up
kubectl scale deployment/web --replicas=4Watch the new pods come up:
kubectl get pods -l app=webExpected output once all four are ready:
NAME READY STATUS RESTARTS AGE
web-<hash>-<hash> 1/1 Running 0 2m
web-<hash>-<hash> 1/1 Running 0 15s
web-<hash>-<hash> 1/1 Running 0 15s
web-<hash>-<hash> 1/1 Running 0 15sKubernetes runs the readiness probe on each new pod before marking it READY.
Step 2 — Inspect the Deployment
kubectl get deployment webExpected output:
NAME READY UP-TO-DATE AVAILABLE AGE
web 4/4 4 4 5mREADY 4/4 confirms all four replicas passed the readiness probe and are in the Service endpoints.
Step 3 — Scale back down
kubectl scale deployment/web --replicas=2Kubernetes terminates two pods gracefully:
kubectl get pods -l app=webExpected output:
NAME READY STATUS RESTARTS AGE
web-<hash>-<hash> 1/1 Running 0 3m
web-<hash>-<hash> 1/1 Running 0 3mCheckpoint
You scaled the web Deployment up to 4 replicas and back to 2. The Service automatically updated its endpoint list as pods came and went.
Next: 07 Wrap-up