Perform a Rolling Update and Rollback¶
Goal¶
In this tutorial you will learn how to safely update an application in Kubernetes and roll back to a previous version if something goes wrong.
You will learn how to:
- perform a rolling update
- monitor deployment progress
- roll back to a previous release
Problem¶
Applications often need to be updated with new versions.
Updating containers incorrectly can cause:
- downtime
- service interruptions
- failed deployments
Kubernetes solves this with rolling updates, which gradually replace old pods with new ones.
Architecture¶
During a rolling update Kubernetes replaces pods one at a time.
Traffic continues flowing to healthy pods during the update.
Example:
Prerequisites¶
Ensure:
- Kubernetes cluster is running
kubectlconfigured
Verify access:
Expected output:
Step 1 : Deploy the Initial Application¶
Create a deployment file deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 3
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web
image: nginx:1.21
ports:
- containerPort: 80
Apply the deployment.
Verify the pods.
Example output:
Step 2 : Update the Container Image¶
Update the deployment to use a newer version.
Run:
This triggers a rolling update.Step 3 : Monitor the Rollout¶
Watch the rollout progress.
Expected output:
You can also watch pods being replaced.
You will see new pods created while old pods terminate.
Step 4 : View Deployment History¶
Kubernetes tracks rollout history.
Run:
Example output:
Each update creates a new revision.
Step 5 : Simulate a Failed Deployment¶
Update the image to an invalid version.
Check the pod status.
You may see:
This simulates a broken deployment.Step 6 : Roll Back the Deployment¶
Roll back to the previous working version.
Verify the rollout.
Kubernetes restores the previous working revision.Verify the Rollback¶
Check the running image.
Look for:
Your application is now running the last stable version.What Just Happened¶
Kubernetes performed two important operations:
| Operation | Description |
|---|---|
| Rolling update | Gradually replaced pods with a new version |
| Rollback | Restored a previous deployment revision |
This allows updates without downtime.
Troubleshooting¶
Rollout Stuck
Check deployment status.
Pods Failing
Inspect pod logs.
Image Pull Errors
Verify the image exists.
Clean Up¶
Delete the deployment when finished.
Key Takeaways¶
You learned how to:
- update applications using rolling deployments
- monitor rollout progress
- view deployment revision history
- roll back to a previous version
Rolling updates are the standard deployment strategy in Kubernetes.