Sub topic 7
Stalled and failed rollouts
This chapter assumes you can apply a Deployment manifest, read kubectl describe output, and know that a Deployment creates ReplicaSets. You should also know how readiness probes, maxSurge, and maxUnavailable shape a rolling update, which earlier chapters cover.
What a stalled rollout looks like
A rollout stalls when new Pods never become available. Common causes:
- The image tag does not exist (
ImagePullBackOff). - The container crashes on start (
CrashLoopBackOff). - The readiness probe never succeeds.
- The cluster lacks CPU, memory, or quota for the extra Pods.
With maxUnavailable: 0, as in the web Deployment from this tutorial, the old Pods keep serving traffic while the new ones fail. The rollout is stuck, but users are not affected yet. Without that setting, a stall can cost you capacity as well.
Kubernetes does not stop the rollout, and it does not undo it. The Deployment controller keeps waiting and retrying.
progressDeadlineSeconds
spec.progressDeadlineSeconds sets how long the controller waits for progress before it reports a problem. The default is 600 seconds. The example Deployment sets it to 300.
Progress means the controller created or scaled a ReplicaSet, or a new Pod became ready. If none of that happens within the deadline, the controller adds a condition to the Deployment's status:
Type: Progressing
Status: False
Reason: ProgressDeadlineExceededOnly the status changes. The controller does not delete anything or roll back, and it keeps trying. If the cause is fixed later, for example the missing image gets pushed, the rollout can still finish.
Keep progressDeadlineSeconds larger than minReadySeconds. The API rejects a Deployment where it is not.
Reproducing and diagnosing a failure
Point the Deployment at an image tag that does not exist:
kubectl set image deployment/web web=nginx:1.27-doesnotexist
kubectl rollout status deployment/web --timeout=330s
echo "exit code: $?"After the deadline passes, rollout status prints error: deployment "web" exceeded its progress deadline and exits with a non-zero code. This makes it suitable for CI pipelines, which can fail the job and trigger a rollback.
To find the cause, work from the Deployment down to the Pods:
kubectl describe deployment web
kubectl get pods -l app=web
kubectl describe pod -l app=web
kubectl get events --sort-by=.lastTimestampIn the describe pod output, the Events section names the problem, such as Failed to pull image or Readiness probe failed. For a crashing container, add kubectl logs <pod> --previous.
You can also read the condition directly:
kubectl get deployment web \
-o jsonpath='{.status.conditions[?(@.type=="Progressing")].reason}'Recovering
You have two options. If the cause is minor and you know the fix, correct the manifest and apply it. That creates a new revision and restarts the rollout. If you need service restored first, run:
kubectl rollout undo deployment/web
kubectl rollout status deployment/webThe undo is itself a rollout. It succeeds quickly when the old ReplicaSet's Pods are still running, and the condition returns to Progressing=True with reason NewReplicaSetAvailable.
Exercise
A Deployment has maxSurge: 1, maxUnavailable: 0, and four replicas. You roll out an image with a typo in the tag. After the deadline, what is the state of the old Pods, what does the Deployment report, and what command restores the previous version?
Show answer
The four old Pods keep running and serving traffic, because maxUnavailable: 0 forbids removing them before replacements are ready. One new Pod sits in ImagePullBackOff. The Deployment gets the condition Progressing=False with reason ProgressDeadlineExceeded, and kubectl rollout status exits non-zero. Run kubectl rollout undo deployment/web to return to the previous revision.