Rolling update
Swap instances a few at a time.
The Kubernetes default. New pods are added and old pods removed in small batches. Two settings, maxSurge and maxUnavailable, set the trade-off between extra cost and reduced capacity. Users never see downtime, but for a while they are served by a mix of old and new code.
0.0s / 16s
Step 1 of 5: Steady state. 4 v1 pods share all traffic behind the Service.
- Availability
- 100%
- No downtime
- Pods running
- 1.00×
- Peak 1.00× of normal
- Blast radius
- —
- Inject a bug to measure
- Time to recover
- —
- No incident
v1 (current)v2 (new)StartingSucceededFailed
Trade-offs
More filled is better for you- Uptime during deploy
- 4 out of 4.Zero downtime with good probes
- Low infra cost
- 3 out of 4.Only the surge (e.g. +25%)
- Rollback speed
- 1 out of 4.Another rolling update, pod by pod
- Small blast radius
- 2 out of 4.Grows as the rollout advances
- Simplicity
- 4 out of 4.Built in, the default
- One version at a time
- 1 out of 4.Mixed versions mid-rollout
Pros and cons
Pros
- Zero downtime with no extra tooling. It's the default Deployment behaviour.
- Cheap. You pay at most for maxSurge extra pods, and only during the rollout.
- Tunable: trade speed, cost and spare capacity with two numbers.
Cons
- Old and new versions serve traffic at the same time, so they must be compatible.
- No traffic control. A pod's share of users depends on how many pods you run, not on a percentage you pick.
- Rollback is slow. It's just another rolling update in reverse.
- Readiness probes only catch crashes, not business bugs. A broken release keeps rolling.
When to reach for it
Use it when
- Stateless services where versions N and N+1 are compatible.
- You want zero downtime without paying for a second environment.
- Most everyday releases of a well-tested service.
Avoid it when
- Breaking API or schema changes between versions.
- You need to cap exposure at a specific percentage, or roll back instantly. Look at Canary or Blue-Green instead.
How to do it
apiVersion: apps/v1
kind: Deployment
metadata:
name: shop
spec:
replicas: 4
minReadySeconds: 10 # must stay ready this long to count
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # at most 5 pods during the rollout
maxUnavailable: 0 # never fewer than 4 ready
selector:
matchLabels: { app: shop }
template:
metadata:
labels: { app: shop }
spec:
terminationGracePeriodSeconds: 30
containers:
- name: shop
image: registry.example.com/shop:2.0.0
readinessProbe: # gates traffic to the new pod
httpGet: { path: /healthz, port: 8080 }
periodSeconds: 2
lifecycle:
preStop: # let the load balancer catch up before exit
exec: { command: ["sleep", "5"] }Gotchas
- Without a readinessProbe, Kubernetes sends traffic to pods before the app is listening. That's errors on every rollout.
- maxSurge: 0 and maxUnavailable: 0 together is invalid. Something has to give.
- Long-lived connections (WebSockets, gRPC streams) stay pinned to old pods until they drain. Use a preStop hook and graceful shutdown.
- Set minReadySeconds so a pod that crashes 10 seconds after start doesn't count as healthy.