Sub topic 10
Waiting for and verifying the rollout
This chapter assumes you can read a GitHub Actions workflow and know what a Deployment, a ReplicaSet, and a readiness probe are. The earlier chapters showed how the pipeline runs kubectl set image. Here you make the job report whether the release actually worked.
Why the deploy step is not enough
kubectl set image only updates the Deployment's desired state. It returns as soon as the API server accepts the change, which is usually within a second. The new Pods may not exist yet, and they may never become healthy. If the job stops there, GitHub shows a green check for a broken release.
kubectl rollout status closes that gap. It watches the Deployment and blocks until the rollout finishes. It exits with code 0 on success and a non-zero code on failure or timeout, and a non-zero exit fails the workflow step.
What "complete" means
A rollout is complete when these are all true:
- All replicas are updated to the new Pod template.
- No old replicas remain.
- All new replicas are available, which means they passed their readiness probe.
The last point matters most. Without a readinessProbe, Kubernetes treats a Pod as ready as soon as its containers start. A crash-looping or misconfigured app can then look healthy for a moment. Define a probe so that "ready" reflects whether the app can serve traffic.
spec:
progressDeadlineSeconds: 120
template:
spec:
containers:
- name: web
image: ghcr.io/example/shop:latest
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 5Two timeouts
Two separate limits apply, and they behave differently.
| Setting | Where it lives | Effect |
|---|---|---|
| `--timeout=120s` | `kubectl rollout status` flag | The client stops waiting and exits non-zero. The rollout itself keeps going. |
| `progressDeadlineSeconds` | Deployment spec | The controller marks the rollout `ProgressDeadlineExceeded` if no progress is made. The default is 600 seconds. |
Set --timeout a little above the time a healthy rollout needs. Keep it consistent with progressDeadlineSeconds. If the client timeout is far shorter, the job fails while Kubernetes is still rolling out.
Adding diagnostics
When a rollout fails, the log of rollout status says little. Add a step that runs only on failure and prints the evidence.
- name: Update image
run: kubectl set image deployment/web web="$IMAGE:$GITHUB_SHA" -n shop
- name: Wait for rollout
run: kubectl rollout status deployment/web -n shop --timeout=120s
- name: Show diagnostics
if: failure()
run: |
kubectl get pods -n shop -l app=web
kubectl describe deployment/web -n shop
kubectl logs deployment/web -n shop --tail=50The if: failure() condition runs the step only when an earlier step failed. Your Role must allow reading Pods, logs, and events for these commands to work. The Role from the RBAC chapter covers only Deployments, so add pods, pods/log, and events with get and list if you want this step.
Common errors
- The job passes but the app is broken. There is no readiness probe, or the probe checks something trivial.
ImagePullBackOff. The tag was not pushed, or the cluster has no pull credentials.rollout statuswill wait until the timeout.- Timeout on a slow start. The
--timeoutvalue is shorter than the image pull plusinitialDelaySeconds. kubectlrejects the command with a Forbidden error. The deployer needsget,list, andwatchon Deployments.rollout statususeswatch.
A failed rollout status leaves the cluster running a mix of old and new Pods. The old Pods keep serving traffic, so users are usually unaffected. The next chapters cover reverting.
Exercise
Your deploy job runs kubectl set image and then finishes green, yet the new Pods are in CrashLoopBackOff. Which step is missing, and which Deployment setting makes the result trustworthy?
Show answer
Add a kubectl rollout status deployment/web -n shop --timeout=120s step so the job fails when the rollout does not complete. Add a readinessProbe so new Pods only count as available when the app can serve traffic.