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

  1. Update the container image or configuration.
  2. Apply the manifest or run kubectl set image.
  3. Monitor the rollout status.
  4. 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 maxUnavailable to 0 for strict zero downtime.
  • Use readiness probes to prevent traffic to new Pods before they are ready.
  • Use minReadySeconds to 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.