Fix the Rolling Update: unsafe maxSurge/maxUnavailable
The situation
The web Deployment in the kubelings namespace serves production traffic, but
every release causes a brief total outage. Its RollingUpdate strategy is set to
maxSurge: 0 and maxUnavailable: 100% — so on each rollout Kubernetes is allowed
to terminate all pods before any replacement is Ready, and is not allowed
to surge a single extra pod to cover the gap.
┌───────────────────┐
│old pods terminate │
│ │
└───────────────────┘
│
maxUnavailable 100%
│
▼
┌─────────────┐
│0 pods Ready │
│ │
└─────────────┘
│
maxSurge 0, no cover
│
▼
┌───────────────┐
│new pods start │
│ │
└───────────────┘
Your task
Make web's rolling update zero-downtime:
- Set
maxSurgeso at least one new pod can start before old ones go away. - Set
maxUnavailableso the whole fleet can't be taken down at once. - Keep the Deployment Available (all 3 replicas Ready).
kubectl -n kubelings get deploy web -o yaml | less
Hint
Edit the strategy, e.g.:
kubectl -n kubelings patch deploy web --type=merge -p \
'{"spec":{"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":"25%"}}}}'
maxSurge ≥ 1 lets a replacement come up first; maxUnavailable < 100% keeps
capacity during the roll.
Solution
Root cause
web's RollingUpdate strategy was maxSurge: 0 + maxUnavailable: 100%. That
combination lets a rollout delete every pod at once (100% unavailable) while
forbidding any extra pod from starting first (0 surge) — a guaranteed outage on
every deploy.
Fix
kubectl -n kubelings patch deploy web --type=merge -p \
'{"spec":{"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":"25%"}}}}'
or kubectl -n kubelings edit deploy web and set:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 25%
Verify
kubectl -n kubelings rollout status deploy/web
kubectl -n kubelings get deploy web \
-o jsonpath='{.spec.strategy.rollingUpdate}{"\n"}'
- Previous lesson
- kubectl detective: find the broken one
- Next lesson
- Build a Node-Level Log Collector DaemonSet