4.01 Rolling Updates and Rollbacks
Kubernetes Deployments provide builtβin support for safe upgrades and fast recovery using:
- β Rolling Updates β upgrade without downtime
- βͺ Rollbacks β revert to a previous working version
Each change to a Deployment creates a new revision, so Kubernetes can track versions and switch back if needed.
π― What Is a Rollout
A rollout is triggered whenever a Deployment is created or its Pod template changes.
A rollout happens when you:
- Create a Deployment
- Change container image
- Modify labels / env / command
- Change pod template fields
Each rollout creates:
- A new ReplicaSet
- A new revision number
Note
Think of a rollout as a new version release of your Deployment inside the cluster.
π§± Deployment Revision Model
Every Deployment keeps a history of ReplicaSets (versions).
Deployment
β
ββ Revision 1 β ReplicaSet A β Pods (v1)
ββ Revision 2 β ReplicaSet B β Pods (v2)
ββ Revision 3 β ReplicaSet C β Pods (v3)
- Only one ReplicaSet serves full traffic after rollout completes
- Older ReplicaSets are kept for rollback
Tip
ReplicaSets are the βversion historyβ behind a Deployment.
π Deployment Strategies
Kubernetes supports two upgrade strategies.
π΄ Recreate Strategy
All old pods are deleted first, then new pods are created.
Flow
Behavior
- Simple
- Causes application downtime
- Not default
Warning
Users will experience outage during upgrade with Recreate strategy.
π’ Rolling Update Strategy (Default)
Pods are replaced gradually.
Flow
Old: βββββ
Step1: βββββ + β
Step2: βββββ + ββ
Step3: βββββ + βββ
New: βββββ + βββββ
Behavior
- Old and new pods run together temporarily
- No downtime (if readiness probes are correct)
- Default strategy
Success
RollingUpdate is used automatically if no strategy is specified.
βοΈ Strategy Configuration (YAML)
π How to Update a Deployment
You can trigger a new rollout in two main ways.
Method 1 β Update YAML and Apply
Edit Deployment YAML, then:
Kubernetes will:
- Create new ReplicaSet
- Start rollout
- Create new revision
Method 2 β Update Image Directly
Tip
Fast for quick updates, but your YAML file will not reflect this change automatically.
π Rollout Status and History
Check rollout progress
View revision history
Example:
Example
Useful to identify which revision to roll back to.
π§© What Happens During Rolling Update
Behind the scenes Kubernetes creates a new ReplicaSet and shifts traffic gradually.
Start:
ReplicaSet A β 5 pods (v1)
During:
ReplicaSet A β 3 pods
ReplicaSet B β 2 pods
Later:
ReplicaSet A β 1 pod
ReplicaSet B β 4 pods
End:
ReplicaSet A β 0 pods
ReplicaSet B β 5 pods (v2)
π View ReplicaSets
You will observe:
- Old ReplicaSet scaled down
- New ReplicaSet scaled up
βͺ Rollback a Deployment
If a new version is broken, revert instantly.
Kubernetes will:
- Scale down new ReplicaSet
- Scale up previous ReplicaSet
- Restore last working version
Success
Rollback is fast because old ReplicaSet already exists.
βͺ Rollback Flow
Current β ReplicaSet B β bad version β 5 pods
Rollback β
ReplicaSet B β scaled to 0
ReplicaSet A β scaled to 5
Previous version restored
π οΈ Command Cheat Sheet
Create
List
Update
Status
Rollback
π§ Exam Tips
Question
Default deployment strategy?
RollingUpdate
Question
What creates a new revision?
Any Pod template change
Question
Does rollback create new pods?
Yes β previous ReplicaSet pods are scaled up again.
β Quick Summary
Summary
- Rollout = new Deployment revision
- Each rollout creates a new ReplicaSet
- RollingUpdate is default
- Recreate causes downtime
- rollout status shows progress
- rollout history shows revisions
- rollout undo restores previous version