Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Running Applications  ›  Lesson

Deployments

Deployments 12 minA Deployment manages ReplicaSets and rolls out pod template changes gradually, keeping the old ReplicaSet so it can roll back.

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:

  1. creates a new ReplicaSet for the new template;
  2. scales the new one up and the old one down, a few pods at a time;
  3. keeps the old ReplicaSet at zero pods, so it can roll back.
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  • maxSurge — how many extra pods may exist above replicas during the update.
  • maxUnavailable — how many pods may be missing below replicas.

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 notes

The 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.

Shipping notes-web 1.3Step 1 of 4
  1. Change the image

    kubectl set image edits 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.

quick drill

What does a Deployment directly manage?

quick drill

Which change starts a rollout of notes-web?

quick drill

replicas: 4, maxSurge: 1, maxUnavailable: 0. What is the most pods that can exist during an update?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWalk a rollout

notes-web has replicas: 3, maxSurge: 1, maxUnavailable: 0. Describe what happens step by step when you change the image from 1.2 to 1.3, and how you would go back if 1.3 fails.