Skip to content
LF Cert Trainer

Lesson 15 · Section 2: Core Concepts

Lesson 15: Pods: the smallest thing Kubernetes runs

What a Pod really is, why Kubernetes wraps containers in one, how a Pod gets from kubectl to a running container, and the commands that create and debug Pods fast in the exam. · 20 min read · 4 min video

1/10Pods
0:00 / 3:40

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why Pods exist

A container is one isolated process. Real applications are often a little more than that: a web server and the agent that ships its logs, an application and the proxy that encrypts its traffic, a service and the helper that reloads its configuration. Those processes are separate programs with separate images, but they only make sense together: they must run on the same machine, talk to each other cheaply, read the same files, and start and stop as one.

Kubernetes could have scheduled containers one by one and let you tie them together with rules. Instead it made the group itself the unit. A Pod is that group: one or more containers that Kubernetes always places on the same node, gives one shared IP address, and creates and deletes as a whole. Most Pods hold a single container, and that is fine. The wrapper still matters, because everything else in Kubernetes (scheduling, networking, storage, scaling, Services) is defined in terms of Pods, never in terms of containers.

What a Pod is made of

What is inside a PodPod web (10.244.1.7)one IPlocalhostnetworkwritesreadsOther Podscall 10.244.1.7:80Container nginxlistens on :80Container shippersends the logs awaypause containerholds IP 10.244.1.7Volume logsemptyDir
What is inside a Pod. The containers of a Pod share one IP address and can share volumes. A hidden pause container holds the network, so the IP survives when an app container restarts.

Parts:

  • Other Pods (call 10.244.1.7:80)
  • Container nginx (listens on :80), in Pod web (10.244.1.7)
  • Container shipper (sends the logs away), in Pod web (10.244.1.7)
  • pause container (holds IP 10.244.1.7), in Pod web (10.244.1.7)
  • Volume logs (emptyDir), in Pod web (10.244.1.7)

Connections:

  • Other Pods to Container nginx: one IP
  • Container nginx and Container shipper: localhost
  • pause container to Container nginx: network
  • Container nginx to Volume logs: writes
  • Container shipper to Volume logs: reads
  • Containers. Each has its own image, its own filesystem and its own resource limits. A crash in one does not kill the others.
  • One network identity. Every container in the Pod sees the same network interface, the same IP address and the same port space. Two containers in one Pod reach each other on localhost, and for the same reason they cannot both listen on port 80. Every Pod in the cluster gets its own IP, and Pods reach each other directly, without NAT.
  • Volumes. A volume is declared once on the Pod and mounted by any container that needs it. This is how two containers share files; their own filesystems stay separate.
  • One spec, one fate. The Pod's containers are scheduled together onto one node, and deleting the Pod deletes them all.

What "sharing" means in practice:

Shared by all containers in the PodSeparate per container
IP address, ports and localhostImage and root filesystem
Hostname (the Pod's name)Command, arguments and environment
Volumes declared in the Pod (when mounted)CPU and memory requests and limits
Node, restart policy, service accountProbes, restart count, logs

Processes are not shared by default: a container cannot see the other containers' processes unless the Pod sets shareProcessNamespace: true.

Under the hood · The hidden pause container

When the kubelet starts a Pod, the container runtime first creates a Pod sandbox: a tiny container that runs the pause image (registry.k8s.io/pause) and does nothing but sleep. Its job is to own the Pod's Linux namespaces, above all the network namespace that the CNI plugin wires up and gives an IP.

Your containers are then started inside those namespaces. That explains several things you will observe:

  • A container that crashes and restarts keeps the same Pod IP, because the sandbox, not your container, holds the network.
  • On a node, crictl pods lists sandboxes and crictl ps lists containers; crictl ps never shows pause, but crictl pods has one line per Pod.
  • If the sandbox itself dies, the kubelet rebuilds the whole Pod on that node, and then the IP can change.
  • The status ContainerCreating usually means the sandbox is still being set up: the network plugin has not answered, a volume cannot be mounted, or the image is still being pulled.

How a Pod comes to life

From kubectl run to a running containerNode worker-1create Podstorebind to nodewatch, reportCRIstartsYoukubectl run webAPI serverchecks and storesetcdPod savedSchedulerpicks worker-1kubeletsees its new Podcontainerdsandbox, imagesPod webRunning
From kubectl run to a running container. Nobody tells the next component what to do. Each one watches the API server and acts when it sees a Pod that needs its work.

Parts:

  • You (kubectl run web)
  • API server (checks and stores)
  • etcd (Pod saved)
  • Scheduler (picks worker-1)
  • kubelet (sees its new Pod), in Node worker-1
  • containerd (sandbox, images), in Node worker-1
  • Pod web (Running), in Node worker-1

Connections:

  • You to API server: create Pod
  • API server to etcd: store
  • Scheduler to API server: bind to node
  • kubelet to API server: watch, report
  • kubelet to containerd: CRI
  • containerd to Pod web: starts

No component orders another around. Each one watches the API server and reacts to what it sees:

  1. kubectl sends the Pod to the API server, which authenticates you, checks your permissions, runs admission (defaults such as the service account are filled in here), validates the object and stores it in etcd. At this moment the Pod exists but spec.nodeName is empty, and its phase is Pending.
  2. The scheduler watches for Pods without a node. It filters out nodes that cannot run the Pod (not enough CPU or memory, taints, node selectors), scores the rest, and writes its choice back by binding the Pod to a node.
  3. The kubelet on that node watches for Pods bound to its node. Through the CRI it asks the container runtime (containerd) to create the sandbox, the CNI plugin gives it an IP, volumes are mounted, images are pulled, init containers run to completion, and then the application containers start.
  4. The kubelet keeps reporting the Pod's status back to the API server. That status is what kubectl get pods prints.

This chain is worth knowing by heart, because every stuck Pod is stuck at one of these steps, and the step tells you which component to look at.

  1. Pending, no node: scheduler
  2. ContainerCreating: kubelet, CNI, volumes
  3. ImagePullBackOff: registry or image name
  4. CrashLoopBackOff: your container
Where a stuck Pod is waiting

Phases, states and the STATUS column

The five Pod phasesPendingscheduling, pullingRunninga container startedSucceededall exited with 0Failedone exited non-zeroUnknownnode unreachable
The five Pod phases. A restarting container does not change the phase: a Pod in CrashLoopBackOff is still in the Running phase.

Parts:

  • Pending (scheduling, pulling)
  • Running (a container started)
  • Succeeded (all exited with 0)
  • Failed (one exited non-zero)
  • Unknown (node unreachable)

Connections:

  • Pending to Running
  • Running to Succeeded
  • Running to Failed
  • Running to Unknown

A Pod has one phase, a coarse summary of where it is in its life:

PhaseMeaning
PendingAccepted by the cluster, but not all containers have started: still unscheduled, or pulling images
RunningBound to a node and at least one container is running, starting or restarting
SucceededEvery container exited with code 0 and none will be restarted
FailedEvery container has stopped and at least one failed (non-zero exit or killed by the system)
UnknownThe node stopped reporting, so the state cannot be read

Each container also has a state: Waiting (with a reason, such as ImagePullBackOff), Running, or Terminated (with an exit code and a reason, such as Completed, Error or OOMKilled).

What "restart" really means

The Pod's restartPolicy tells the kubelet what to do when a container exits. It applies to every container in the Pod.

restartPolicyThe kubelet restarts a container whenTypical use
Always (default)it exits, for any reason, even with code 0Servers, anything in a Deployment
OnFailureit exits with a non-zero codeJobs that should retry
NeverneverOne-off commands, test Pods

The restart happens inside the same Pod on the same node: same name, same UID, same IP, and the RESTARTS counter goes up. To avoid hammering the node, the kubelet waits longer after each crash: 10 seconds, 20, 40, and so on up to five minutes. While it waits, the status reads CrashLoopBackOff. A container that then runs cleanly for ten minutes gets its delay reset.

Under the hood · Why a bare Pod is not self-healing

Restarting a container is the kubelet's job, and the kubelet only exists on its node. Nothing in a Pod's definition asks the cluster to keep a Pod existing:

  • If the node fails, the Pod is eventually marked for deletion and it is gone. No component creates another one.
  • A Pod is never moved. "Rescheduling" always means that a controller created a new Pod, with a new name, a new UID and a new IP, and the old one was deleted.
  • If you delete the Pod, or the node evicts it because memory or disk runs short, it stays gone.

A ReplicaSet, Deployment, StatefulSet, DaemonSet or Job adds exactly that missing piece: a controller that notices a missing Pod and creates a replacement from a template. This is the "self-healing" the CKA curriculum talks about, and the next lessons build on it. Create bare Pods for tests, debugging and exam tasks that ask for one; run everything else through a controller.

One container or several

The rule of thumb: put two containers in one Pod only if they cannot work apart. Ask whether they must scale together. A web application and its database do not: you want five web replicas and one database, so they are two Pods. A web server and the agent that tails its log files do: they are one Pod.

PatternWhat the extra container doesExample
SidecarExtends the main container for the Pod's whole lifeLog shipper, service mesh proxy
Init containerRuns to completion before the app containers startWait for a database, fetch configuration
Ephemeral containerAdded to a running Pod for debugging, never restartedkubectl debug with a toolbox image

Init containers run one after another, and each must succeed before the next starts; a failing one shows as Init:Error or Init:CrashLoopBackOff in the STATUS column. A sidecar is written as an init container with restartPolicy: Always: it starts before the application containers, keeps running next to them and is stopped after them.

Using it

Example · Create a Pod and check every layer

Run nginx in a Pod called web, then confirm where it runs and that it answers.

kubectl run web --image=nginx:1.29 --port=80 --labels=app=web
kubectl get pod web -o wide              # READY, STATUS, RESTARTS, IP and NODE
kubectl describe pod web                 # spec, container states, and Events at the bottom
kubectl logs web                         # what the container printed
kubectl exec -it web -- sh               # a shell inside the container

--port only records the container port in the spec; it opens nothing and exposes nothing. In kubectl get, READY 1/1 means one of one containers passes its readiness check. A Pod can be Running and 0/1: started, but not ready for traffic.

Example · Run a one-off command in a throwaway Pod

Check from inside the cluster that the Pod answers on its IP, without leaving anything behind.

kubectl run tmp --rm -it --restart=Never --image=busybox:1.37 -- wget -qO- http://10.244.1.7

--restart=Never makes the Pod finish instead of restarting when the command exits, -it attaches your terminal, and --rm deletes the Pod afterwards. Everything after -- is passed to the container as arguments. Add --command when the first word should replace the image's entrypoint:

kubectl run sleeper --image=busybox:1.37 --command -- sleep 3600

Example · Find out why a Pod does not start

A Pod api in namespace shop never becomes ready. Work from the outside in:

kubectl -n shop get pod api                      # 1. STATUS and RESTARTS
kubectl -n shop describe pod api                 # 2. Events, and State / Last State per container
kubectl -n shop logs api --previous              # 3. output of the run that crashed
kubectl -n shop get pod api -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}'
What you seeWhat it meansWhere to look
Pending, no NODENo node fitsFailedScheduling event: resources, taints, node selector
ContainerCreating for longSandbox, network or volume not readyEvents: missing ConfigMap, Secret or volume claim; CNI
ErrImagePull, ImagePullBackOffImage cannot be pulledImage name, tag, registry, pull secret
CrashLoopBackOffContainer starts, then exitslogs --previous, the exit code, the command
Running but 0/1Readiness probe failsProbe settings in describe, the app's port
OOMKilled, exit code 137Memory limit exceededresources.limits.memory

Exit codes worth recognising: 0 finished normally, 1 the application reported an error, 127 the command was not found (a typo in command), 137 killed with SIGKILL (often out of memory), 143 stopped with SIGTERM.

Example · Change a Pod that is already running

Only a few fields of a live Pod can be changed: the container images, activeDeadlineSeconds, and added tolerations. Everything else, such as the command, environment, ports, volumes or labels in a selector you depend on, needs a new Pod.

kubectl set image pod/web web=nginx:1.30         # allowed in place: the container restarts
kubectl get pod web -o yaml > web.yaml           # for anything else: export,
vi web.yaml                                      # edit,
kubectl replace --force -f web.yaml              # and delete + recreate in one step

If you try the forbidden change with kubectl edit, the save is rejected and kubectl keeps your version in a file under /tmp; kubectl replace --force -f on that file finishes the job.

Tricks

Common mistakes

  • Expecting a bare Pod to come back. A deleted or evicted Pod, or one on a failed node, is gone. If the task says "ensure it keeps running", it wants a Deployment.
  • Reading Running as "works". Running only says a container has started. Check READY and RESTARTS as well: 0/1 or a climbing restart count means trouble.
  • Reading the wrong logs. After a crash, kubectl logs shows the new attempt, which may be empty. The reason is in kubectl logs --previous.
  • Forgetting --restart=Never on one-off Pods. With the default Always, a command that finishes is restarted again and again, and the Pod ends up in CrashLoopBackOff although nothing failed.
  • Mixing up arguments and command. Without --command, the words after -- become arguments to the image's entrypoint. With an image that has an entrypoint, -- sleep 3600 may be passed to it as options and fail.
  • Two containers on the same port. They share one port space, so the second one fails to bind and crash-loops.
  • Forgetting the namespace. A Pod "not found" is usually in another namespace. Try kubectl get pods -A.

Recap

  • A Pod is one or more containers that share an IP address, volumes and a lifetime, always on one node.
  • The API server stores it, the scheduler places it, the kubelet runs it through the container runtime.
  • The kubelet restarts containers in place according to restartPolicy; a Pod itself is never moved or repaired, which is why workloads run under controllers.
  • Phases are Pending, Running, Succeeded, Failed, Unknown; the STATUS column shows the more useful container reason.
  • In the exam: kubectl run with --dry-run=client -o yaml, then get -o wide, describe, logs --previous, and replace --force when a field cannot be edited.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Run a Pod, look inside it, and get a Pod that will not start running again.

    Build · Level 1 · warm-up · target 10 min

  • Get answers out of two pods that listen only on their own loopback address, one of them built from an image without a shell, with kubectl debug, port-forward and exec.

    Investigate · Level 2 · standard · target 20 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.