By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
(Rolling Updates, Rollbacks, and Production-Grade Kubernetes)
You’re a DevOps engineer at a SaaS company. Your team just pushed a buggy release to production, and now your app is crashing under load. Users are complaining, your boss is Slack-pinging you, and the on-call engineer is frantically checking logs.
Here’s the problem:- Your app runs in Kubernetes.- You manually scaled Pods up/down, but now you have no way to safely roll back to the last stable version.- If you delete Pods, Kubernetes doesn’t automatically replace them (unless you’re using a ReplicaSet).- If you update the app, Kubernetes doesn’t gradually replace Pods (unless you’re using a Deployment with a rolling update strategy).
This guide fixes that.- ReplicaSets ensure a fixed number of Pods are always running (self-healing).- Deployments manage ReplicaSets and enable rolling updates (zero-downtime deploys) and rollbacks (instant recovery from bad releases).- Without these, you’re either: - Manually managing Pods (error-prone, unscalable). - Risking downtime during updates (bad for users, worse for your reputation).
Real-world scenario:You’re deploying a new version of your API. The old version (v1) is running in production. You need to: 1. Deploy v2 without downtime.2. Roll back to v1 instantly if v2 crashes.3. Scale up/down without manual intervention.
v1
v2
This guide shows you how.
rs
deploy
maxSurge
maxUnavailable
kubectl rollout
kubectl rollout status
kubectl rollout undo
kubectl rollout history
strategy
RollingUpdate
Recreate
revisionHistoryLimit
10
0
5
minReadySeconds
✅ A running Kubernetes cluster (Minikube, Kind, EKS, GKE, AKS, etc.).✅ kubectl installed and configured.✅ A simple Docker image (we’ll use nginx:1.23 and nginx:1.24).
kubectl
nginx:1.23
nginx:1.24
We’ll deploy nginx:1.23 with 3 replicas.
nginx-deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.23 ports: - containerPort: 80
kubectl apply -f nginx-deploy.yaml
kubectl get deployments kubectl get pods kubectl get rs # Check the ReplicaSet
Expected output:
NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 3/3 3 3 10s NAME READY STATUS RESTARTS AGE nginx-deploy-5f7d8c6b5c-abc12 1/1 Running 0 10s nginx-deploy-5f7d8c6b5c-def34 1/1 Running 0 10s nginx-deploy-5f7d8c6b5c-ghi56 1/1 Running 0 10s NAME DESIRED CURRENT READY AGE nginx-deploy-5f7d8c6b5c 3 3 3 10s
We’ll update the image to nginx:1.24 without downtime.
Option 1: Edit the YAML and re-apply
# Change `image: nginx:1.23` → `image: nginx:1.24` kubectl apply -f nginx-deploy.yaml
Option 2: Use kubectl set image (faster)
kubectl set image
kubectl set image deployment/nginx-deploy nginx=nginx:1.24
kubectl rollout status deployment/nginx-deploy
Waiting for deployment "nginx-deploy" rollout to finish: 1 out of 3 new replicas have been updated...Waiting for deployment "nginx-deploy" rollout to finish: 2 out of 3 new replicas have been updated...deployment "nginx-deploy" successfully rolled out
kubectl get pods -o wide # Check Pod IPs (old Pods are replaced) kubectl describe deployment nginx-deploy | grep Image # Confirm new image
Image: nginx:1.24
Suppose nginx:1.24 has a bug. Let’s roll back to nginx:1.23.
kubectl rollout history deployment/nginx-deploy
deployment.apps/nginx-deploy REVISION CHANGE-CAUSE 1 <none> 2 <none>
kubectl rollout undo deployment/nginx-deploy --to-revision=1
kubectl rollout status deployment/nginx-deploy kubectl describe deployment nginx-deploy | grep Image
Image: nginx:1.23
By default, Kubernetes: - Creates 1 new Pod at a time (maxSurge: 25%).- Allows 1 Pod to be unavailable (maxUnavailable: 25%).
maxSurge: 25%
maxUnavailable: 25%
Let’s customize this for faster updates (but higher risk).
spec: strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 # Create 1 extra Pod during update maxUnavailable: 0 # Never allow Pods to be unavailable
kubectl describe deployment nginx-deploy | grep -A 3 Strategy
StrategyType: RollingUpdate RollingUpdateStrategy: 1 max unavailable, 1 max surge
readOnlyRootFilesystem: true
securityContext
runAsNonRoot: true
imagePullSecrets
replicas
30
kubectl delete rs <old-rs-name>
progressDeadlineSeconds
600
kubectl rollout pause
app: frontend
env: prod
CrashLoopBackOff
kubectl get events --sort-by=.metadata.creationTimestamp
minReadySeconds: 30
matchLabels
selector does not match template labels
spec.selector.matchLabels
spec.template.metadata.labels
❌ Nothing (⚠️ trap answer).
"How do you roll back a Deployment to the previous version?"
kubectl rollout undo deployment/<name>
❌ kubectl delete deployment/<name> (⚠️ destroys the Deployment).
kubectl delete deployment/<name>
"What’s the difference between maxSurge and maxUnavailable?"
maxUnavailable: How many Pods can be down during an update.
"What’s the default Deployment strategy?"
❌ Recreate (⚠️ trap answer).
"How do you check the rollout history of a Deployment?"
kubectl rollout history deployment/<name>
kubectl get deployments
maxUnavailable: 0
You have a Deployment (webapp) running nginx:1.23 with 5 replicas. You need to: 1. Update it to nginx:1.24 without downtime.2. Pause the rollout after 2 Pods are updated (for debugging).3. Resume the rollout after verifying the new Pods are healthy.
webapp
# 1. Update the image (rolling update starts) kubectl set image deployment/webapp nginx=nginx:1.24 # 2. Pause the rollout after 2 Pods are updated kubectl rollout pause deployment/webapp # 3. Verify 2 new Pods are running kubectl get pods # Should show 2 new Pods (nginx:1.24) and 3 old Pods (nginx:1.23) # 4. Resume the rollout kubectl rollout resume deployment/webapp # 5. Verify all Pods are updated kubectl rollout status deployment/webapp
Why it works:- kubectl set image triggers a rolling update.- kubectl rollout pause stops the update mid-way (useful for debugging).- kubectl rollout resume continues the update.
kubectl rollout resume
kubectl create deployment <name> --image=<image>
kubectl create deployment nginx --image=nginx:1.23
kubectl get deploy -o wide
kubectl get rs
kubectl get rs -l app=nginx
kubectl set image deployment/<name> <container>=<image>
kubectl set image deployment/nginx nginx=nginx:1.24
kubectl rollout status deployment/<name>
kubectl rollout status deployment/nginx
kubectl rollout history deployment/nginx
kubectl rollout undo deployment/nginx
kubectl rollout undo deployment/<name> --to-revision=<N>
kubectl rollout undo deployment/nginx --to-revision=1
kubectl rollout pause deployment/<name>
kubectl rollout pause deployment/nginx
kubectl rollout resume deployment/<name>
kubectl rollout resume deployment/nginx
kubectl describe deployment <name>
kubectl describe deployment nginx
kubectl delete deployment <name>
kubectl delete deployment nginx
⚠️ Exam Traps:- kubectl delete pod <name> does not trigger a rollback (ReplicaSet recreates the Pod).- kubectl edit deployment does not pause a rollout (use kubectl rollout pause).- maxSurge: 0 is invalid (must be at least 1 or a percentage).
kubectl delete pod <name>
kubectl edit deployment
maxSurge: 0
1
ReplicaSets and Deployments are the backbone of reliable Kubernetes apps. Master them, and you’ll: - Eliminate downtime during updates.- Recover instantly from bad releases.- Scale effortlessly without manual intervention.
Now go deploy something. ?
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.