Skip to content

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

Old Pods β†’ deleted β†’ ❌ downtime β†’ New Pods created

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)

strategy:
  type: RollingUpdate
strategy:
  type: Recreate

πŸ”„ 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:

kubectl apply -f deployment.yaml

Kubernetes will:

  • Create new ReplicaSet
  • Start rollout
  • Create new revision

Method 2 β€” Update Image Directly

kubectl set image deployment/myapp nginx=nginx:1.9.1

Tip

Fast for quick updates, but your YAML file will not reflect this change automatically.


πŸ“Š Rollout Status and History

Check rollout progress

kubectl rollout status deployment/myapp

View revision history

kubectl rollout history deployment/myapp

Example:

REVISION   CHANGE-CAUSE
1          initial deploy
2          image update

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

kubectl get replicasets

You will observe:

  • Old ReplicaSet scaled down
  • New ReplicaSet scaled up

βͺ Rollback a Deployment

If a new version is broken, revert instantly.

kubectl rollout undo deployment/myapp

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

kubectl create -f deployment.yaml

List

kubectl get deployments

Update

kubectl apply -f deployment.yaml
kubectl set image deployment/myapp nginx=nginx:1.9.1

Status

kubectl rollout status deployment/myapp
kubectl rollout history deployment/myapp

Rollback

kubectl rollout undo deployment/myapp

🧠 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