Rolling update
- Docker & Kubernetes course
- Intermediate
- Lesson 28/82
- 4 min
Learn Deployment image updates.
Rolling update
When the pod template changes (e.g. the image), the Deployment does a rolling update: it opens a pod in the new ReplicaSet and, once it's ready, closes one of the old ones. Two settings determine speed and safety:
maxSurge: at most how many extra pods can be opened above the desired count.maxUnavailable: at most how many pods can be out of service during the update.
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0maxUnavailable: 0 guarantees capacity never drops.
Updating the image
The fastest way is kubectl set image; but for a lasting record, editing the YAML and running apply is better. An annotation can be added to write the reason for the change into the history:
kubectl set image deployment/web nginx=nginx:1.27.3
kubectl annotate deployment/web kubernetes.io/change-cause="nginx 1.27.3'e yükseltme"
kubectl rollout status deployment/webPractice A safe update
Write three commands: set the image of the nginx container in the web deployment to nginx:1.27.3; add the kubernetes.io/change-cause annotation as "nginx 1.27.3"; wait for the rollout to finish.
Starter code
# buraya yazSample solution
kubectl set image deployment/web nginx=nginx:1.27.3
kubectl annotate deployment/web kubernetes.io/change-cause="nginx 1.27.3"
kubectl rollout status deployment/webExpected output
deployment.apps/web image updated deployment.apps/web annotated Waiting for deployment "web" rollout to finish: 1 out of 3 new replicas have been updated... deployment "web" successfully rolled out
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 If the readiness check (readinessProbe) always fails on new pods, what does the rolling update do?
- It stalls; the old pods keep serving Correct answer
- It closes all the old pods
- It rolls back automatically
- It ignores readiness
Explanation: The old pod isn't closed until a new one is ready; after progressDeadlineSeconds the deployment is marked failed.
2 Change the container's image.
kubectl set image deployment/web ____=nginx:1.27.3
kubectl set image deployment/web nginx=nginx:1.27.3
Explanation: The form is container_name=new_image.
3 Match.
| Term | Meaning |
|---|---|
maxSurge |
Extra pod limit |
maxUnavailable |
Unavailable pod limit |
set image |
Change image |
change-cause |
Reason for change |