Pods
Every workload in Kubernetes — a web server, a database, a nightly backup — ends up as pods. Understand the pod and every higher-level object becomes "a thing that makes pods".
The rule
A pod is one address shared by containers that live and die together.
A pod wraps one or more containers that:
- share one IP address and port space, so they reach each other on
localhost; - can share volumes (directories);
- are always scheduled onto the same node and started and stopped as a unit.
Most pods hold one container. A second one is added only when it is a close helper — for example a sidecar that ships the main container's log files.
apiVersion: v1
kind: Pod
metadata:
name: notes-web
namespace: notes
labels:
app: notes-web
spec:
containers:
- name: web
image: ghcr.io/example/notes-web:1.2
ports:
- containerPort: 8080Pods are disposable. If the node under a pod fails, that pod is gone; a new pod with a new name and a new IP may replace it, but only if something higher up — a Deployment, for instance — asks for one. A bare pod created from the file above is not replaced by anyone.
A pod's status tells its story: Pending (waiting for a node or an image), Running, Succeeded, Failed, and the famous CrashLoopBackOff — the container keeps exiting and Kubernetes waits longer before each restart.
The shortcut
To decide whether two containers belong in one pod, ask: "Must they share a machine and always scale together?" If yes, one pod. If they could live apart, two pods.
notes-web and notes-db
The database scales differently and must outlive web restarts. They can live apart: separate pods.
The trap is packing a whole app (web plus database) into one pod. Scaling the web tier would then clone the database too.
Drills
Answer fast — trust the rule.
How do two containers in the same pod reach each other?
A bare pod (no Deployment) is on a node that dies. What happens?
Which pair belongs in one pod?
A pod shows CrashLoopBackOff. What does that mean?
Remember
- A pod is one address shared by containers that live and die together.
- Same pod only if they must share a machine and scale together.
- Trap: bare pods are not replaced, and web plus database in one pod scale wrongly.
