Kubernetes · Chapter 6 of 28

Rollouts

By the end of this chapter you can ship a new version of a Deployment without dropping requests, choose how fast it goes with maxSurge and maxUnavailable, follow it with kubectl rollout status, read its history and record why each revision exists, pause it, restart it, and roll back a bad release in one command. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Running apps
  • 4 tasks
  • Kubernetes
  • In the all labs plan

The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.

Why you need this

Last October a new catalog reached two of Jhatpat's three machines and stopped; for a day a third of customers saw old prices. Before Diwali, Tushar's team ships a release almost every day: storefront 1.2 with the festival banner, catalog 1.3 with a new price table. Ritika wants each release to reach every customer, or none, and no customer to see an error while it happens. Ammar wants to be able to say which version is running, why, and to go back in a minute when a release is bad.

From chapter 5 you know that a Deployment makes a new ReplicaSet when its template changes. But how fast are old pods replaced, how many may be missing at a time, what happens when the new version cannot even start, and how do you go back? Deleting and recreating pods by hand is exactly the half-finished deploy of last October. This chapter is the Deployment's rollout: the part that moves pods from the old ReplicaSet to the new one, safely.

What you build: 4 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    Storefront 1.2 with zero unavailable

    Roll Ammar's storefront to the new version without ever having fewer than 4 pods ready.

    1. Give the storefront Deployment a RollingUpdate strategy with maxUnavailable 0 and maxSurge 1.

    2. Change its image to jhatpat/storefront:1.2. Do this after step 1, or in the same change.

    3. Use storefront.yaml with kubectl apply -f, or kubectl patch and kubectl set image.

    4. Run kubectl rollout status deployment/storefront until it finishes.

    To pass: the storefront Deployment has the image jhatpat/storefront:1.2, a RollingUpdate strategy with maxUnavailable 0 and maxSurge 1 or more, and 4 replicas. The rollout has finished: all 4 pods run the new version and are ready. Do not delete the Deployment and make it again.

  2. Task 2

    Catalog 1.3, see it fail, undo

    Try a new catalog version, see it fail, and go back to the old one.

    1. Change the catalog Deployment's image to jhatpat/catalog:1.3.

    2. List the pods. Read the new pod's logs with kubectl logs and --previous to see why it fails.

    3. Go back with kubectl rollout undo deployment/catalog.

    4. Wait until the 3 catalog pods of 1.2 are ready.

    To pass: catalog has a revision with jhatpat/catalog:1.3, so it was tried. The Deployment runs jhatpat/catalog:1.2 again, with 3 ready pods. You ran kubectl rollout undo, and the command worked. Do not set the image back to 1.2 by hand, and do not delete the Deployment.

  3. Task 3

    Record why each revision exists

    Write down why each revision of storefront and catalog exists.

    1. Right after each change, set the annotation kubernetes.io/change-cause on the Deployment, with kubectl annotate and --overwrite.

    2. The reason must name the version the new pods run: 1.2 for storefront, 1.3 for catalog.

    3. Set catalog's reason for 1.3 before you run rollout undo. The annotation goes to the revision that is current at that moment.

    4. Run kubectl rollout history on both Deployments to check.

    To pass: in kubectl rollout history, every revision of storefront and of catalog has a CHANGE-CAUSE, and each one names the version its pods run (1.1, 1.2 or 1.3). This is true for every revision, even one you made by mistake. Revision 1 of each already has one.

  4. Task 4 · interview question

    Interview: maxUnavailable 0 and maxSurge 1

    Ammar will ask: "With 4 replicas, maxUnavailable 0 and maxSurge 1, what does the rollout do, step by step?"

    1. Write two or three sentences in your own words in answer.txt, below the notes.

    2. Say how many pods run at most during the rollout, and how many stay available at least.

    3. Say in what order new pods are made and old pods are removed.

    To pass: answer.txt gives the largest number of pods and the smallest number of available pods, as numbers or words, and says the order of the steps.

What you will learn

  • Starting a rollout: kubectl set image, editing the template, kubectl apply.
  • RollingUpdate: maxSurge and maxUnavailable, step by step; Recreate in one paragraph.
  • Watching it: kubectl rollout status, the ReplicaSets, minReadySeconds, progressDeadlineSeconds.
  • History: kubectl rollout history, revisions, and the change-cause annotation.
  • Going back: kubectl rollout undo and --to-revision.
  • pause, resume and restart.

More in Running apps

Build "Rollouts" yourself

Jhatpat delivers groceries in ten minutes from 14 dark stores across Lucknow, and its hand-run servers fall over on festival evenings. You move it onto Kubernetes. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.