Kubernetes Deployments and Safe Rollouts
A Deployment tells Kubernetes how many copies of a Pod should run and which image they use. The Deployment controller creates a ReplicaSet for each version, then gradually shifts Pods from the old set to the new one.
Create and inspect a Deployment:
bash kubectl create deployment web --image=nginx:1.27 --replicas=3 kubectl get deployments,replicasets,pods -l app=web kubectl rollout status deployment/web
To release a new version, change the image and watch the rollout:
bash kubectl set image deployment/web nginx=nginx:1.27.2 kubectl rollout status deployment/web --timeout=120s
If the new version misbehaves, return to the previous revision:
bash kubectl rollout history deployment/web kubectl rollout undo deployment/web
Two settings control how fast Pods are replaced. maxSurge is how many extra Pods may exist during the update, and maxUnavailable is how many may be missing. Set both in the strategy section of the manifest.
A readiness probe matters here. Kubernetes only counts a Pod as available after its readiness probe passes, so a probe that checks the real application health prevents a broken version from receiving traffic.
Keep the previous ReplicaSet around as well, because the revision history limit controls how many old versions remain available for rollback. Set it with revisionHistoryLimit in the Deployment spec.