TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

All concepts ยท infrastructure ยท devops ยท containers

Kubernetes

A container orchestrator. You declare the desired state (which images, how many copies, how to reach them) and controllers keep the cluster matching it by scheduling, restarting, scaling and rolling out updates.

11 min3 animations

๐Ÿ“š Builds on๐Ÿ“ฆ Docker and containers

๐Ÿ–จ๏ธ Cheat sheet

A note for the harbour master

You don't dock ships yourself. You give the harbour master a note: "I want three of these ships docked at all times." The harbour master looks at the harbour, sees none, and calls three in, choosing berths with room.

Desired state

Containers solve packaging; running hundreds of them across many machines needs an orchestrator. In Kubernetes you write declarative manifests:

1apiVersion: apps/v12kind: Deployment3metadata: { name: orders }4spec:5  replicas: 36  selector: { matchLabels: { app: orders } }7  template:8    metadata: { labels: { app: orders } }9    spec:10      containers:11        - name: orders12          image: shop/orders:1.4

kubectl apply stores it in the control plane (API server backed by etcd). The scheduler places pods (one or more containers) on nodes, and the kubelet on each node runs them.

The harbour master's list2 steps
๐Ÿง‘โ€โœˆ๏ธShip ownerโš“Harbour master
Press play and watch it happen!

A ship sinks

The harbour master keeps checking. When a ship sinks, nobody has to phone you: the gap is spotted and a replacement is called in. The note still says three, so there will be three.

Reconciliation

Kubernetes is a set of control loops. Each controller watches actual state and acts to make it match desired state. A crashed container is restarted; a pod lost with its node is recreated elsewhere; a failing liveness probe triggers a restart. The same loop powers scaling: change replicas, or let a HorizontalPodAutoscaler change it based on CPU.

A ship sinks3 steps
โš“Harbour master๐ŸšขShip 1๐ŸšขShip 2๐ŸšขShip 3
Press play and watch it happen!

Swapping the fleet

To upgrade, one new ship docks, and only once it's ready does it take cargo. Then one old ship leaves. Repeat until the fleet is new. The harbour gate never closes.

Services and rolling updates

Pods come and go with new IPs, so a Service gives a stable name and load-balances across ready pods matching a label. An Ingress or Gateway routes outside HTTP traffic to Services.

Changing the image triggers a rolling update: new pods start and join the Service once their readiness probe passes, old pods drain and stop. A bad release stalls the rollout, and kubectl rollout undo rolls back. Config and secrets come from ConfigMaps and Secrets.

Swapping the fleet, one ship at a time3 steps
๐ŸšชHarbour gate๐ŸšขOld ship A๐ŸšขOld ship B
Press play and watch it happen!

๐Ÿงฉ Quick quiz

Quick quiz! 3 questions about Kubernetes, told the same way as the story.
  1. What does your note to the harbour master say?
  2. A ship sinks. What happens?
  3. How is the fleet upgraded without closing the harbour gate?
Answer every question to check.Passing marks Kubernetes as done.
Got the hang of Kubernetes? Mark it as done, and your paths show how far youโ€™ve got.

Saved in this browser.

๐Ÿš€ Shipping to productionStep 5 of 10

โ† Previous on the path๐Ÿ“ฆ Docker and containersNext on the path โ†’๐Ÿข Service mesh

๐Ÿ‘‰ Read next

  • ๐Ÿš›Amazon ECS, Fargate and EKSA port with working berths for containers: bring your own lorries or rent one by the trip.
  • ๐ŸขService meshA concierge at every flat door who checks badges, retries deliveries and logs every one.