Pods in depth

Intermediate · 8 min

What a Pod is, its phases, conditions and container states, restart policy and crash back-off, what you can change, and why you rarely create one directly.

Before thisNodes, the kubelet and the container runtimeThe Kubernetes API and object model

Microsoft Developer · 8 min

Pods in depth

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Microsoft DeveloperReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A Pod is a group of containers that share a network namespace (one IP, one port space, localhost between them), can share volumes, and are always scheduled onto the same node together.
  • Pod phase is a coarse summary (Pending, Running, Succeeded, Failed, Unknown). The detail lives in conditions (PodScheduled, PodReadyToStartContainers, Initialized, ContainersReady, Ready) and per-container states.
  • restartPolicy Always, OnFailure or Never decides what the kubelet does when a container exits. Restarts back off from 10 seconds, doubling to 5 minutes, and reset after 10 minutes of running; that wait is CrashLoopBackOff.
  • Since 1.35, per-container restartPolicy and restartPolicyRules (beta, on by default) can restart one container on specific exit codes regardless of the Pod's policy.
  • Most of a Pod's spec is immutable after creation. Images, activeDeadlineSeconds and added tolerations can change; resources change through the resize subresource; everything else means a new Pod.
  • A Pod is bound to one node for life and is not rescheduled when that node dies. That is why you run Pods through a controller.

Why not just containers?

Kubernetes could have scheduled containers directly. It doesn’t, because real applications often need a few processes that must live together: an app and a log shipper reading its files, a web server and a proxy in front of it, a main process and a helper that refreshes credentials. They need to share a network address and a disk, start on the same machine, and be scheduled as one unit. Scheduling them separately and hoping they land together would be fragile.

So the smallest thing Kubernetes runs is a Pod: one or more containers deployed together, sharing some namespaces. The name comes from a pod of whales. The core objects lesson introduced it; this lesson goes into how it behaves.

What containers in a Pod share

The kubelet builds each Pod around a sandbox, as the nodes lesson showed. Inside it, containers share:

  • The network namespace. One IP address and one port space. Containers reach each other on localhost, and two of them cannot both bind port 8080.
  • IPC, so they can use shared memory.
  • Volumes declared at the Pod level, mounted by whichever containers name them.
  • Optionally the PID namespace, with shareProcessNamespace: true, so one container can see and signal another’s processes.

Each container keeps its own filesystem from its own image, its own resource limits and its own restart history. Think of a Pod as a shared flat: one street address and one front door, shared kitchen cupboards if you agree to them, but separate bedrooms.

A sample Pod with an app and a log shipper:

apiVersion: v1
kind: Pod
metadata:
  name: web
  labels: {app: web}
spec:
  restartPolicy: Always
  terminationGracePeriodSeconds: 30
  containers:
  - name: app
    image: ghcr.io/example/web:2.1.0
    ports: [{containerPort: 8080}]
    resources:
      requests: {cpu: 100m, memory: 128Mi}
      limits: {memory: 256Mi}
  - name: log-shipper
    image: fluent/fluent-bit:4.0
    restartPolicy: Never
    restartPolicyRules:
    - action: Restart
      exitCodes: {operator: In, values: [42]}

Phase, conditions and container states

Status has three layers, and confusing them is the root of many debugging mistakes.

Phase is one word for the whole Pod: Pending (accepted but not all containers started, which includes waiting for scheduling and pulling images), Running (bound to a node, at least one container running or restarting), Succeeded (all containers exited 0 and won’t restart), Failed (all exited, at least one with an error) and Unknown (the node stopped reporting).

Conditions say which milestones the Pod has passed:

Condition True when
PodScheduled A node has been chosen
PodReadyToStartContainers The sandbox and its network are set up (GA in 1.37)
Initialized All init containers finished
ContainersReady Every container passes its readiness check
Ready The Pod can receive Service traffic

Container states are per container: Waiting (with a reason such as ContainerCreating, ImagePullBackOff or CrashLoopBackOff), Running, or Terminated (with exit code and reason such as OOMKilled).

The lab Pod above, applied to a cluster whose node has no kubelet, shows the first layer only:

$ kubectl get pod web -o wide
NAME   READY   STATUS    RESTARTS   AGE   IP       NODE
web    0/2     Pending   0          2s    <none>   fake-1
$ kubectl get pod web -o jsonpath=...
PodScheduled=True
phase=Pending qos=Burstable

The scheduler did its part and set PodScheduled. Every later condition is written by the kubelet, which isn’t there, so the Pod stays Pending forever. When you see a real Pod stuck in Pending, the conditions tell you which side is stuck: no PodScheduled means a scheduling problem; PodScheduled=True but nothing further points at the node, image pulls or volumes.

Restart policy and CrashLoopBackOff

When a container exits, the kubelet consults restartPolicy: Always (the default, for services), OnFailure (restart only on non-zero exit, for batch work) or Never. Restarts are delayed by an exponential back-off. In the v1.37.3 kubelet source the delay starts at 10 seconds, doubles each time, caps at 300 seconds, and resets once a container has run for 10 minutes. The CrashLoopBackOff you see is the kubelet waiting out that delay, not a separate failure.

So a Pod can be in phase Running while its container is Waiting: CrashLoopBackOff. The STATUS column in kubectl get pods shows the most specific reason it can find, which is why it says CrashLoopBackOff instead of Running.

Two newer knobs refine this. Per-container restartPolicy and restartPolicyRules (the ContainerRestartRules feature, beta and on by default since 1.35) let one container be restarted on chosen exit codes even under a Pod-level Never, which the lab API server accepted for the log-shipper above. And the KubeletCrashLoopBackOffMax feature (beta in 1.35) lets a node administrator lower the 300-second cap.

What you can change on a live Pod

Very little. Trying to add an environment variable:

$ kubectl patch pod web --type=json -p '[{"op":"add","path":"/spec/containers/0/env",...}]'
The Pod "web" is invalid: spec: Forbidden: pod updates may not change fields other than
`spec.containers[*].image`,`spec.initContainers[*].image`,`spec.activeDeadlineSeconds`,
`spec.tolerations` (only additions to existing tolerations),`spec.terminationGracePeriodSeconds` ...

kubectl set image pod/web app=ghcr.io/example/web:2.1.1 was accepted and bumped the Pod’s generation to 2; the kubelet then restarts that one container with the new image. CPU and memory can be changed in place through the resize subresource, GA since 1.35 and covered in vertical scaling and in-place resize. Anything else means deleting the Pod and creating a new one with a new UID and usually a new IP.

Why you rarely create Pods yourself

A Pod is bound to one node for its whole life. If that node dies, the Pod is marked for deletion and nothing replaces it. If you delete it, it is gone. That is acceptable for a one-off debug Pod and nothing else. Real workloads run Pods through a controller that creates them from a template and replaces them: a Deployment for stateless services, a StatefulSet for stable identities, a DaemonSet for one per node, a Job for run-to-completion work. The rest of this group covers each.

About the video

The embed is Microsoft Developer’s “How Pods and the Pod Lifecycle work in Kubernetes” (October 2019, 8 minutes). Its description calls Pods the atomic unit of scheduling and promises what happens when you create a Pod and how the Pod lifecycle works, which matches the first half of this lesson. It was judged from that description; there are no chapters. It predates native sidecar containers, per-container restart rules, the PodReadyToStartContainers condition and in-place resize, all of which the lesson adds. English was judged from the “English (US) original” audio track and manual English captions. Nana’s video in deeper covers the networking side of the shared-flat picture: localhost between containers and the pause container.

What was run: the two-container Pod, its PodScheduled condition and Burstable QoS class, the acceptance of restartPolicyRules, the immutability error and the image update ran against a local v1.37.3 API server whose node runs no containers, on 2026-11-28. Phases, container states and restart behaviour need a kubelet, so they are written from the Pod lifecycle docs, and the back-off numbers and feature stages from the v1.37.3 source.

Where this fits

Some containers in a Pod have special jobs: running first, or alongside the app for its whole life. Next: init containers and sidecar containers.

Check yourself

  1. 01A Pod shows STATUS CrashLoopBackOff and phase Running. How can both be true?

    Phase is a coarse summary. With restartPolicy Always, a Pod whose container keeps exiting stays in phase Running, while that container sits in the Waiting state with reason CrashLoopBackOff during the kubelet's restart delay. The STATUS column in kubectl get shows the most informative reason, not the phase.

  2. 02Two containers in one Pod both try to listen on port 8080. What happens?

    The second fails to bind, because they share one network namespace, and so one port space. Containers in a Pod talk to each other over localhost and must use different ports.

  3. 03You try to add an environment variable to a running Pod with kubectl edit. Why is it rejected, and what should you do instead?

    Pod specs are mostly immutable; the API server allows only image, activeDeadlineSeconds, tolerations additions and a few others. Change the Pod template in the Deployment, which replaces the Pod with a new one.

  4. 04A node fails and its bare Pod (no Deployment) is gone. Will Kubernetes recreate it elsewhere?

    No. A Pod is bound to a node for its whole life. The node controller eventually marks it for deletion, but nothing creates a replacement unless a controller such as a ReplicaSet, StatefulSet or Job owns it.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark