Rolling Update Strategy
What you'll learn: You'll learn how to fine-tune rolling updates using maxSurge and maxUnavailable to balance update speed with service availability.
The Core Idea
When you update a Deployment, Kubernetes doesn't immediately shut down all old Pods and start new ones—that would cause downtime. Instead, it gradually replaces them using a rolling update strategy. Two key parameters control this behavior:
maxSurge: How many extra Pods above the desired replica count can exist temporarily during the updatemaxUnavailable: How many Pods can be unavailable during the update
Think of it like renovating a restaurant: maxSurge is how many extra tables you can temporarily squeeze in while replacing old ones, and maxUnavailable is how many tables can be out of service at once. You balance customer capacity with renovation speed.
How They Work Together
Both settings can be absolute numbers (e.g., 2) or percentages (e.g., 25%). Here's what happens:
- Higher
maxSurge: More new Pods spin up before old ones terminate → faster updates, more resources used temporarily - Lower
maxUnavailable: Fewer Pods go down at once → better availability, slower updates - Aggressive update:
maxSurge: 50%,maxUnavailable: 0(never lose capacity) - Conservative update:
maxSurge: 1,maxUnavailable: 0(one-by-one replacement) - Balanced:
maxSurge: 25%,maxUnavailable: 25%(Kubernetes default)
Configuration Example
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
This allows up to 5 Pods total (4 + maxSurge) and tolerates 3 available (4 - maxUnavailable) during updates.
Key Takeaway: maxSurge and maxUnavailable give you precise control over how fast your Deployment updates roll out and how much capacity fluctuation you'll tolerate—tune them based on your application's availability requirements and resource constraints.