Sub topic 6
Watching a rollout with kubectl rollout status
This chapter assumes you can apply YAML manifests and use kubectl get and kubectl describe. It also assumes you know that a Deployment owns ReplicaSets, and that a change to the Pod template starts a rollout. The goal here is to follow a rollout while it runs and to recognize when it has stopped making progress.
Start a rollout and follow it
Apply the web Deployment from the earlier chapters, then change its image. The image is part of the Pod template, so this creates a new ReplicaSet and starts a rolling update.
kubectl apply -f web.yaml
kubectl set image deployment/web web=nginx:1.27
kubectl rollout status deployment/webkubectl rollout status blocks until the rollout finishes or fails. It prints a line each time the counts change:
Waiting for deployment "web" rollout to finish: 1 out of 4 new replicas have been updated...
Waiting for deployment "web" rollout to finish: 2 out of 4 new replicas have been updated...
Waiting for deployment "web" rollout to finish: 3 old replicas are pending termination...
deployment "web" successfully rolled outThe exit code matters in scripts and CI. It is 0 when the rollout completes. It is non-zero when the rollout fails, for example when the progress deadline passes.
What the command reads
The command compares fields in the Deployment's status. You can read the same fields yourself:
kubectl get deployment web
kubectl get replicasets -l app=webThe Deployment columns mean:
| Column | Meaning |
|---|---|
| READY | Pods that pass their readiness probe, out of the desired count |
| UP-TO-DATE | Pods that match the current Pod template |
| AVAILABLE | Ready Pods that have also stayed ready for `minReadySeconds` |
A rollout is complete when all replicas are updated, no old replicas remain, and all updated replicas are available. With maxSurge: 1 and maxUnavailable: 0, you will briefly see five Pods in total. The new ReplicaSet's count rises while the old one's count falls.
Recognizing a stalled rollout
A rollout stalls when new Pods never become ready. Typical causes are a wrong image tag, a failing readiness probe, or a lack of cluster resources. Set a bad image to see it:
kubectl set image deployment/web web=nginx:does-not-exist
kubectl rollout status deployment/web --timeout=60sThe command keeps printing the same "Waiting" line and then exits with a timeout error. The old Pods keep serving traffic, because maxUnavailable: 0 forbids removing a ready Pod before its replacement is ready. The rollout is stuck, but the application is still up.
Once progressDeadlineSeconds (300 seconds in our manifest) passes without progress, the Deployment gets a condition with reason ProgressDeadlineExceeded, and rollout status reports it and exits non-zero. The Deployment controller does not roll back by itself. It only reports the failure.
Finding out why
Work from the Deployment down to the Pod:
kubectl describe deployment web
kubectl get pods -l app=web
kubectl describe pod <pod-name>In the Deployment's Conditions, look at the Progressing entry. In the Pod's Events, look for ErrImagePull, ImagePullBackOff, FailedScheduling, or Readiness probe failed. The Pod events usually name the actual cause.
After you find the cause, either fix the template and apply it again, or roll back, which a later chapter covers.
Exercise
A rollout shows "Waiting for deployment "web" rollout to finish: 2 out of 4 new replicas have been updated..." for several minutes, and the application still answers requests. What does that combination tell you, and what is your first command to find the cause?
Show answer
The new Pods are not becoming ready, but the old Pods are still serving because maxUnavailable is 0 and ready Pods were not removed. Run kubectl get pods -l app=web to find the failing Pods, then kubectl describe pod <pod-name> and read the Events for the cause, such as an image pull error or a failing readiness probe.