Learning Kubernetes From Scratch (Part 10) – Rolling Updates & Rollbacks
By Newt / April 12, 2026 / No Comments / Kubernetes
π Kubernetes Rolling Updates & Zero Downtime Deployments
This is one of the most important concepts in Kubernetes β deploying updates without breaking your app.
- π Deploy new versions safely
- π’ Keep your app running during updates
- β©οΈ Instantly roll back if something fails
Kubernetes replaces pods gradually, not all at once β this is how zero downtime works.
βοΈ 1. Create the Deployment
This deployment runs 4 replicas of nginx and uses a rolling update strategy.
π File: 01-rolling-updates.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
labels:
app: web-app
spec:
replicas: 4 # Always keep 4 pods running
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # Allow 1 extra pod during update
maxUnavailable: 1 # Allow 1 pod to go down
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: nginx
# Initial version of the app
image: nginx:1.14
ports:
- containerPort: 80
# Only send traffic when pod is ready
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
This setup ensures:
- π’ Your app always has running instances
- π Updates happen gradually
- π¦ Traffic only hits ready pods
π Apply the Deployment
kubectl apply -f 01-rolling-updates.yaml
π 2. Expose the App (Service)
To properly test rolling updates, we need a stable way to access the app. This is where a Service comes in.
π File: 02-service.yaml
apiVersion: v1
kind: Service
metadata:
name: web-app-service
spec:
type: NodePort
selector:
app: web-app # Targets our deployment pods
ports:
- port: 80
targetPort: 80
nodePort: 30007 # External port
This creates a stable endpoint that always routes traffic to healthy pods.
π Apply the Service
kubectl apply -f 02-service.yaml
π Access the App
minikube service web-app-service
Now open the app in your browser β keep it open for the next step π
π 3. Perform a Rolling Update (Live Test)
Now we upgrade the app while itβs running.
kubectl set image deployment/web-app nginx=nginx:1.25 --record
π Watch Pods
kubectl get pods -l app=web-app -w
While this runs:
- π Refresh your browser
- π Notice: no downtime
Kubernetes creates new pods first, waits for them to be ready, then removes old ones.
π 4. View Deployment History
kubectl rollout history deployment web-app
Kubernetes tracks every deployment revision β this is what makes rollbacks possible.
β©οΈ 5. Rollback (When Things Go Wrong)
Letβs simulate a bad deployment:
kubectl set image deployment/web-app nginx=nginx:broken-version --record
Now fix it instantly:
kubectl rollout undo deployment web-app
Your app recovers without downtime π₯
π§ Key Concepts
| Concept | What it means |
|---|---|
| Kubernetes Rolling Updates | Gradual pod replacement |
| maxSurge | Extra pods allowed during update |
| maxUnavailable | Pods allowed to go down |
| Rollback | Revert to previous version |
π§Ή Cleanup
kubectl delete -f 01-rolling-updates.yaml kubectl delete -f 02-service.yaml
π§ Final Thoughts
This is how real production systems deploy safely every day.
- π Zero downtime deployments
- π Safe rollbacks
- π’ High availability
