Kubernetes Basics
Pods, Deployments, and Services - how Kubernetes keeps containers running at scale.
On this page5 sections
Docker Compose is great for one machine. Kubernetes (often "k8s") solves the much harder problem: running containers reliably across a whole cluster of machines, automatically replacing them when they fail.
Pods
The smallest unit Kubernetes schedules is a Pod - one or more containers that always run together, on the same machine, sharing the same network address. Almost always, that's exactly one container per Pod.
Deployments
You don't create Pods directly in practice - you create a Deployment, and tell it how many copies (replicas) of a Pod you want running:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
template:
spec:
containers:
- name: web
image: nginx:1.25
If a Pod crashes, or the machine it's on dies, the Deployment notices and starts a replacement - without anyone paging a human in the middle of the night to do it by hand. Change replicas: 3 to replicas: 10 and apply it again, and Kubernetes starts seven more, on whichever machines in the cluster have room.
Services
Pods come and go, and each one gets a new IP address every time it's replaced - so nothing else in the cluster can reliably point directly at one. A Service gives a stable name and address that always routes to whichever Pods are currently healthy, no matter how many times they've been replaced underneath it.
Rolling updates
Pushing nginx:1.26 over the top of nginx:1.25, a Deployment replaces Pods a few at a time by default - never all at once - so there's no moment where zero healthy Pods are serving traffic.
Try it
Everything above ultimately runs as ordinary containers on an ordinary Linux node:
docker ps
When you're ready, hit Mark complete and move to the next lesson.
Challenge
A Kubernetes node is, underneath, just running containers - list every currently-running container on this host.
Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.
Quiz
Lock in the concepts. Score at least 80% to mark the lesson complete.
Done with this one?
Skipped the challenge? You can mark the lesson complete by hand.