Rolling Updates
When you update your application, you want to do it without downtime. Deployments provide rolling updates that gradually replace old Pods with new ones, ensuring availability during the update.
How Rolling Updates Work
When you change the Pod template (e.g., image tag), the Deployment creates a new ReplicaSet with the updated spec. It then scales up the new ReplicaSet while scaling down the old one, ensuring a certain number of Pods are always available.
Performing a Rolling Update
Assuming you have a Deployment with image
nginx:1.21, update to nginx:1.22:kubectl set image deployment/nginx-deployment nginx=nginx:1.22Alternatively, edit the YAML directly:kubectl edit deployment nginx-deploymentMonitoring the Update
Watch the rollout status:
kubectl rollout status deployment nginx-deploymentYou’ll see messages like Waiting for rollout to finish: 2 out of 3 new replicas have been updated...Rollback
If the update fails or causes issues, you can roll back to the previous revision:
kubectl rollout undo deployment nginx-deploymentTo see revision history:kubectl rollout history deployment nginx-deploymentUpdate Strategy Configuration
You can control the update behavior with
strategy in the Deployment spec. For example, to allow more flexibility:spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0Two Minute Drill
- Rolling updates replace old Pods gradually to avoid downtime.
- Update image:
kubectl set image deployment/name container=newimage. - Check status:
kubectl rollout status deployment/name. - Rollback:
kubectl rollout undo deployment/name. - Configure update strategy with
maxSurgeandmaxUnavailable.
Need more clarification?
Drop us an email at career@quipoinfotech.com
