Deployments
The notes team ships version 1.3. With a bare ReplicaSet you would have to delete old pods and create new ones yourself, and users would see errors in between. A Deployment makes the switch gradually and remembers how to go back.
The rule
A Deployment swaps ReplicaSets gradually: new one up, old one down.
A Deployment looks almost like a ReplicaSet — replicas, selector, template — but it manages ReplicaSets instead of pods.
When you change the pod template (for example the image tag), the Deployment:
- creates a new ReplicaSet for the new template;
- scales the new one up and the old one down, a few pods at a time;
- keeps the old ReplicaSet at zero pods, so it can roll back.
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0maxSurge— how many extra pods may exist abovereplicasduring the update.maxUnavailable— how many pods may be missing belowreplicas.
With the settings above, there are never fewer than 3 ready pods. (Both default to 25% when not set.)
Everyday commands:
kubectl set image deployment/notes-web web=ghcr.io/example/notes-web:1.3 -n notes
kubectl rollout status deployment/notes-web -n notes
kubectl rollout undo deployment/notes-web -n notesThe shortcut
Ask: "Did I change the pod template?" Template change → new ReplicaSet and a rollout. Anything else — such as only changing replicas — just resizes the current ReplicaSet.
Change the image
kubectl set imageedits the template. A new ReplicaSet appears with 0 pods.
The trap is kubectl scale expecting a new version: scaling never changes the template, so it never triggers a rollout.
Drills
Answer fast — trust the rule.
What does a Deployment directly manage?
Which change starts a rollout of notes-web?
replicas: 4, maxSurge: 1, maxUnavailable: 0. What is the most pods that can exist during an update?
Version 1.3 is failing. Which command returns to the previous version fastest?
Remember
- A Deployment swaps ReplicaSets gradually: new one up, old one down.
- Template changed? New ReplicaSet and a rollout. Otherwise, just a resize.
- Trap: scaling never ships a new version.
