The pod
A pod is containers that share one address
One address, shared localhost, shared files. And always replaceable.
Kubernetes never runs a bare container. It wraps it in a pod. Usually that is one container in one pod. The pod, not the container, gets the network address. If a second container is added, it shares that address, and the two talk over localhost as if they were on one small machine. They can also share a volume, which is how a helper reads the logs the web server writes. One rule to remember: a pod is never repaired. It is replaced by a new one, with a new name and a new address.
Init containers and sidecars · Going deeper
Init containers run first, in order; a sidecar is one told to stay
initContainers finish before the main ones start. restartPolicy: Always makes one a sidecar.
Ownership
A Deployment makes a ReplicaSet, which makes the pods
Deployment to ReplicaSet to pods, tied together by labels.
You almost never create pods yourself. You create something that creates them. You write a Deployment: three copies of this image. The Deployment creates a ReplicaSet, whose only job is to keep the count at three. The ReplicaSet creates the pods, and gives each a name beginning with its own. How does it know which pods are its own? Not by name. It has a selector, app equals web, and it counts every pod carrying that label.
Rolling update
A new version replaces the old a few pods at a time
The new ReplicaSet grows as the old one shrinks. Never fewer than three.
Now change the image from one point two seven to one point two eight. The Deployment does not stop everything and start again. It begins with three old pods, in grey. It creates a second ReplicaSet for the new version and starts one pod. When that pod is ready, one old pod is removed, and another new one started. The same again. Until the new set has all three. The old ReplicaSet stays, with no pods, so that you can go back.
Rolling update · Going deeper · 1 of 2
Lab: roll out, then roll back
Change the image, watch the roll-out, then undo it.
maxSurge and maxUnavailable · Going deeper · 2 of 2
Surge rounds up, unavailable rounds down: the sums behind 25%
With 3 replicas: 1 extra, 0 missing. The deadline is 600 seconds.
Other workloads
Choose the workload by how its pods must behave
Deployment, StatefulSet, DaemonSet, Job, CronJob.
Deployments suit programs where every copy is the same. Other work needs other rules, and each rule has its own controller. A Deployment puts identical pods wherever there is room. A StatefulSet numbers its pods and gives each its own storage, for databases. A DaemonSet runs exactly one pod on every node, for agents that collect logs or metrics. A Job runs a task to the end and stops. And a CronJob starts a Job on a timetable.
Jobs and CronJobs · Going deeper
A CronJob as written, with the defaults that catch people out
Five-field schedule, backoffLimit 6, and a restartPolicy that is never Always.
Labels
Labels tag things; selectors find them
A selector is a question. The labels give the answer.
Labels deserve a closer look, because they hold everything together. Here are five pods, each tagged with an app and an environment. The selector app equals web matches three of them. The selector e n v equals prod matches four, across three different apps. And both together match two. The same pods, grouped three ways, and nobody had to list them by name.
Lesson complete
You finished “Pods and Deployments”
Nicely done.