Sub topic 2
What triggers a rollout
This chapter assumes you know Pods, labels, and selectors, can apply YAML manifests, and have used kubectl get, apply, and describe. It also assumes you know how a Deployment manages ReplicaSets, which the previous chapter covered. Here the question is narrower: which edits to a Deployment start a rollout, and which do not.
The rule: only the Pod template counts
A Deployment starts a rollout when, and only when, its Pod template (.spec.template) changes. The controller hashes the template. If the hash matches an existing ReplicaSet, it scales that ReplicaSet up. If it matches none, it creates a new ReplicaSet and begins replacing Pods. The hash appears as the pod-template-hash label and as the suffix of the ReplicaSet name.
What does and does not trigger
| Change | Starts a rollout? |
|---|---|
| Container image or tag | Yes |
| Environment variables, command, args, probes, resources | Yes |
| Labels or annotations under `spec.template.metadata` | Yes |
| `spec.replicas` (scaling) | No |
| `strategy`, `minReadySeconds`, `progressDeadlineSeconds`, `revisionHistoryLimit` | No |
| Annotations on the Deployment's own `metadata` | No |
| Contents of a ConfigMap or Secret that Pods reference | No |
Triggering a rollout from the command line
Changing the image is the usual trigger. This sequence assumes the web Deployment from the topic's example manifest is saved as web.yaml.
kubectl apply -f web.yaml
kubectl set image deployment/web web=nginx:1.27
kubectl annotate deployment/web kubernetes.io/change-cause="upgrade nginx to 1.27" --overwrite
kubectl rollout status deployment/web
kubectl get replicasets -l app=webkubectl set image edits the template, so a second ReplicaSet appears. The old one scales down to 0 but remains for rollback. The annotate command writes to the Deployment's own metadata, not the template, so it records the reason without causing a second rollout.
Common errors
- Scaling and expecting a rollout.
kubectl scaleonly changes the replica count of the current ReplicaSet. Pods are not replaced. - Updating a ConfigMap and expecting new Pods. The Deployment does not watch ConfigMaps. Pods that mount the ConfigMap as a volume may eventually see the new data. Environment variables never update in running Pods. To force a rollout, change the template, for example by putting a hash of the config in a template annotation.
- Re-pushing the same tag. If you push a new image to
nginx:1.26and the template still saysnginx:1.26, nothing changes. Use unique tags or digests. - Editing while paused. A paused Deployment accepts template edits but does not roll them out until you resume. A later chapter covers this.
- Reapplying an unchanged manifest.
kubectl applywith no template difference is a no-op for rollouts.
Forcing a restart without changing the image
When you need fresh Pods with the same spec, use a restart.
kubectl rollout restart deployment/web
kubectl rollout status deployment/webThis works by adding a kubectl.kubernetes.io/restartedAt annotation with the current time to the Pod template. That changes the hash, so it follows the same rule as any other trigger, and it uses your configured strategy.
Exercise
You run kubectl scale deployment/web --replicas=8 and then kubectl annotate deployment/web team=platform. Neither command starts a rollout. Why, and what single change to the Deployment would start one?
Show answer
Scaling changes only spec.replicas, and the annotation is on the Deployment's own metadata. Neither touches .spec.template, so the template hash and ReplicaSet stay the same. Any template edit would start a rollout, for example kubectl set image deployment/web web=nginx:1.27, or adding a label or annotation under spec.template.metadata.