Kubernetes

Kubernetes runs containers across a cluster of machines and keeps the actual state matching the state you declared — restarting, rescheduling and scaling pods for you.

kubectl apply -f deployment.yaml

Deployment web · replicas: 3 · image: web:v1

node-1

node-2

node-3

  • v1 pod
  • v2 pod
  • Just started
  • Crashed / stopped

You declare the desired state: "run 3 copies of web:v1". Kubernetes keeps making reality match it.

Step 1 / 24
Desired pods
3
Running pods
0

Step by step

The example above, written out — the same steps the animation plays.

  1. 1kubectl apply -f deployment.yaml. You declare the desired state: "run 3 copies of web:v1". Kubernetes keeps making reality match it.
  2. 2Schedule web-1 → node-1. The scheduler puts each pod on the node with the most room.
  3. 3Schedule web-2 → node-2. The scheduler puts each pod on the node with the most room.
  4. 4Schedule web-3 → node-3. The scheduler puts each pod on the node with the most room.
  5. 5Service: one address for all three. A Service gives the pods one stable name and spreads traffic across the healthy ones.
  6. 6web-2 crashes. The app inside hit a fatal error. Desired 3, running 2.
  7. 7Replace it: web-4. The ReplicaSet notices the difference and creates a new pod. No pager needed.
  8. 8node-3 goes down. The whole machine is gone, with 1 pod on it.
  9. 9Reschedule → node-1. web-5 starts on a healthy node.
  10. 10kubectl scale --replicas=5. Traffic is up: change the desired count.
  11. 11Scale up: web-6 → node-2. New pods join the Service as soon as they are ready.
  12. 12Scale up: web-7 → node-1. New pods join the Service as soon as they are ready.
  13. 13Deploy web:v2 (rolling update). Replace pods one at a time, so the app never goes down.
  14. 14Start web-8 (v2). A v2 pod starts and passes its readiness check…

…and 10 more steps — press Play above to watch them all.

What's happening?

  1. A Deployment declares "run 3 copies of web:v1"; the scheduler places the pods on nodes.
  2. When a pod crashes or a node dies, controllers see fewer pods than desired and start new ones elsewhere.
  3. Scaling changes the desired count; a rolling update swaps pods to the new version one at a time, with no downtime.

Where you'll meet it

Running microservices at most mid-to-large companies, on EKS, GKE or AKS — and the platform underneath many PaaS products.

Common mistake

Skipping readiness and liveness probes: Kubernetes then sends traffic to pods that aren't ready and keeps dead ones running.

FAQ

Pod vs container?

A pod is the smallest unit Kubernetes runs: one or more containers that share a network address and storage.

What does a Service do?

Gives a changing set of pods one stable name and address, and load-balances across the healthy ones.

What does "declarative" mean here?

You describe what you want, not the steps. Controllers keep comparing and correcting, forever.