Boss lesson · Unit 01
A Deployment for the shop
Replicas, labels and selectors, and a ReplicaSet that replaces what you delete.
What you practise
- Replicas, labels and selectors, a ReplicaSet replacing a deleted pod, why you rarely create a pod yourself
Try a question from this lesson
Pick one
A controller must keep 3 Pods of the shop's web app alive. Pods get random names and are replaced often. How can it tell which Pods are its own to count?
Hint
It must survive a Pod being replaced by one with a new name on a different node.
Correct answer
By a label its Pods carry, which it selects on
Why
Names change with every replacement, nodes are shared with other apps, and two apps can run the same image. A label such as app: web is a tag you choose, and a selector is a query for it: count every Pod tagged this way.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Deployment: a count, a query, a template
A Deployment keeps a set of identical Pods running. Its spec has three parts.
replicas: how many. selector: the label query that finds its Pods. template: the Pod to create when one is missing, written as a Pod manifest without apiVersion and kind.
The template's labels must satisfy the selector, or the Deployment could never find the Pods it makes.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels: {app: web}
spec:
containers:
- name: web
image: shop/web:1.4Concept
Deployment, ReplicaSet, Pods
A Deployment does not create Pods directly. It creates a ReplicaSet, and the ReplicaSet's only job is the count: keep exactly replicas Pods that match the selector.
The Deployment sits above it so that it can swap one ReplicaSet for another when the template changes. That is a rollout, in the last unit.
The names show the chain: a ReplicaSet is the Deployment's name plus a hash of the template, and each Pod adds five random characters.
Deployment web
ReplicaSet web-6b7f9c5d4
Pod web-6b7f9c5d4-x2k9q
Pod web-6b7f9c5d4-h8m4t
Pod web-6b7f9c5d4-p5z7n10 more exercises in the app
- 2× fill the blanks
- 4× multiple choice
- 2× type the answer
- 1× order the lines
- 1× true or false
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.