Kubernetes · Chapter 5 of 28
Deployments
By the end of this chapter you can say what a ReplicaSet does and why you rarely make one yourself, write a Deployment from nothing, scale it, follow the owner references from a pod to its Deployment, and say which changes give a Deployment a new ReplicaSet. 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
On a normal evening the storefront needs 2 pods; from 7 pm on Dhanteras it needs 6, and the catalog behind it must never drop to zero. In chapter 1 you watched Ammar's storefront Deployment bring back a pod you deleted, and in chapter 3 you learnt that a bare pod is made once and never again. Ritika's rule (no empty cart at 9 pm) needs the first kind for every service: something that keeps a number of identical pods alive, and lets Tushar change that number or the version without touching each pod.
What you know so far cannot do it. A pod manifest makes one pod. Ten copies would be ten files to apply, ten pods to watch, and a lost node would still take its pods with it for good. This chapter explains the two objects behind chapter 1's self-healing, the ReplicaSet and the Deployment, and how they find their pods: by the labels of chapter 4.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
catalog.yaml: a Deployment for the catalog
Run the catalog as a Deployment, so the cluster keeps its pods running.
1. Open catalog.yaml. Set replicas to 3.
2. Give the template the label app=catalog, the same label the selector asks for.
3. In the container named catalog, set the image jhatpat/catalog:1.2 and add containerPort 8080.
4. Run kubectl apply -f catalog.yaml.
To pass: a Deployment named catalog in ch05 has 3 replicas, a selector on app=catalog, pods labelled app=catalog, and a container named catalog with that image and port. All 3 pods are ready.
- Task 2
Scale storefront for the evening
More customers come in the evening, so run more storefront pods.
1. Use kubectl scale on Ammar's storefront Deployment. Change it from 2 to 6 replicas.
2. Run kubectl get deploy storefront until READY shows 6/6.
To pass: you ran kubectl scale, and the command worked. The storefront Deployment wants 6 replicas and 6 storefront pods are ready. Its image stays jhatpat/storefront:1.2. Scale the Deployment, not its ReplicaSet, and do not delete it and make it again.
- Task 3
owner.txt: who owns the notifier pods
Find out who owns the notifier pods, and who owns that owner.
1. Run kubectl describe on one notifier pod. The Controlled By line names the ReplicaSet that owns it.
2. Run kubectl describe on that ReplicaSet. Its Controlled By line names what owns it.
3. In owner.txt, below the notes, write two lines.
To pass: the first line is the full name of the ReplicaSet that owns the notifier pods now, as kubectl prints it. The second line is its owner as Kind/name, the way describe prints it. Keep these two lines in this order.
- Task 4 · interview question
Interview: Deployment or ReplicaSet
Ammar will ask: "Why a Deployment and not a ReplicaSet, and what happens inside when a pod dies?"
1. Write two or three sentences in your own words in answer.txt, below the notes.
2. Say why Jhatpat makes Deployments, and what a Deployment adds, such as new versions and history.
3. Say what the ReplicaSet controller does when one of its pods dies.
To pass: answer.txt names the Deployment, and says that a new pod is made when a pod dies.
What you will learn
- ReplicaSet: replicas, a selector and a pod template, kept true by its controller.
- Why you rarely make a ReplicaSet: it never changes the pods it already has.
- Deployment: a ReplicaSet manager, and the selector that must match the template.
- kubectl scale: more or fewer pods in one command.
- Owner references and garbage collection: Deployment, ReplicaSet, Pod, and what deleting does.
- What makes a new ReplicaSet: a change to the pod template, and nothing else.
More in Running apps
Build "Deployments" 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.