How to perform rolling updates in Kubernetes?
· Category: Kubernetes
Short answer
Rolling updates in Kubernetes are managed by Deployments. When the Pod template changes, the Deployment creates a new ReplicaSet and gradually replaces old Pods with new ones, ensuring zero downtime.
Steps
- Update the container image or configuration.
- Apply the manifest or run
kubectl set image. - Monitor the rollout status.
- Roll back if necessary.
Example
kubectl set image deployment/web web=nginx:1.26
kubectl rollout status deployment/web
kubectl rollout history deployment/web
kubectl rollout undo deployment/web
Deployment strategy:
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
Tips
- Set
maxUnavailableto 0 for strict zero downtime. - Use readiness probes to prevent traffic to new Pods before they are ready.
- Use
minReadySecondsto ensure Pods are stable before proceeding.
Common issues
- New Pods may fail readiness probes, stalling the rollout.
- Insufficient cluster resources can block new Pod creation.
- Rollback restores the previous ReplicaSet but not deleted ConfigMaps.