Appearance

The Pod lifecycle

Observe how a Pod groups containers and what changes when a container exits or a Pod is replaced.

What you will understand

  • Explain what containers inside a Pod can share.
  • Read a Pod's phase alongside its container status.
  • Predict how a restart policy handles a failed process.

Builds on: kubectl and your cluster context

What belongs in one Pod

An application listens on port 8080 and a helper needs to make a quick local request to it. Both can run in one Pod. A Pod is the smallest unit Kubernetes schedules onto a node. It may have one container or several cooperating containers. All containers in a Pod share the Pod network namespace. They can reach one another over localhost and they share the port space, so two listeners cannot bind the same address and TCP port there at the same time.

Containers in one Pod can also mount the same volume. Suppose the helper reads a file that the application writes. Each container must mount that volume at a path it can access. A shared emptyDir starts out empty and lives with the Pod. The volume can survive a restart of one container inside that Pod. Deleting the Pod ends the volume’s lifetime. Persistent claims use a different lifetime, which you will see in the storage module.

A Pod object has a name and UID. After a kubelet restarts a container, you can see a higher restart count while the Pod UID stays the same. If a controller replaces the entire Pod, the replacement gets a new UID. That distinction tells you whether you are looking at a fresh process inside the same Pod or a fresh API object.

What two containers share in one Pod

They land together and share a network namespace. Each container must mount a Pod volume before it can read the volume’s files.

  1. One assignment

    Both containers belong to one Pod scheduled on one worker. They are not independently scheduled replicas.

  2. One set of Pod ports

    App and helper use the same Pod IP and port space. localhost reaches peers inside this Pod, not another Pod.

  3. Explicit volume mounts

    Each container has its own root filesystem. Both mount one emptyDir to exchange files during this Pod’s lifetime.

One Linux Pod has two ordinary containers and one disk-backed emptyDir.

Explore another case

Run a container that finishes

The lab below uses a process that prints deliberate-exit and exits with code 7. Save it as lifecycle-demo.yaml in a disposable cluster. It uses restartPolicy: Never so you can read the terminal result without the kubelet retrying the program.

apiVersion: v1
kind: Pod
metadata:
  name: lifecycle-demo
spec:
  restartPolicy: Never # Do not retry this app container after it exits.
  containers:
    - name: worker
      image: busybox:1.36.1
      command: ["sh", "-c", "echo deliberate-exit; exit 7"]
kubectl apply -f lifecycle-demo.yaml
kubectl get pod lifecycle-demo -w
kubectl describe pod lifecycle-demo
kubectl logs lifecycle-demo -c worker
kubectl get pod lifecycle-demo -o jsonpath='{.status.containerStatuses[0].state.terminated}'

The Pod can pass through Pending while getting ready to run. When the process exits, the container’s terminated state reports its exit code, reason, and timestamps. The Pod phase summarizes the Pod as a whole. For this example, expect a Failed phase once the nonzero exit completes. If kubectl get shows a more specific status string, read the underlying phase and container state to understand both.

What changes when a failed process restarts?

A restart gives the container a new process inside the existing Pod. A replacement Pod has a fresh UID and a fresh emptyDir.

  1. A process exits

    • Pod UID P on node-a

    The app exits with code 7. Its container state becomes Terminated while the Pod identity and node binding still exist.

  2. Restart inside the same Pod

    With restartPolicy OnFailure, the kubelet restarts the app container. Repeated immediate exits introduce restart backoff.

  3. Replace the whole Pod

    • Managed Pod P deleted

    For a separate ReplicaSet-managed Pod using Pod-level restartPolicy Always, deletion ends its UID. The ReplicaSet creates Pod Q; scheduling and startup then run for Q. An OnFailure template is not valid for a ReplicaSet.

The local restart frames use a standalone OnFailure Pod with no per-container restart rules. The replacement frame switches to a separate ReplicaSet-managed Pod, whose Pod-level policy must be Always.

Compare container restart policies

Restart policy tells the kubelet when to retry a container after it exits. Never leaves the terminal result. OnFailure retries exits that failed, while Always retries even after a successful exit. Repeated failures usually introduce a delay between retries. To compare outcomes, create a second standalone Pod with a different name and OnFailure in the spec. Watch its restart count and read the previous attempt’s logs. Deployments manage Pods using Always, so keep the finite standalone example separate from Deployment practice.

What lives for the lifetime of a Pod

If the application appeared to vanish, compare its last container termination with the Pod’s UID. A restart normally explains a new process, and a new UID explains a new Pod lifetime. The module lab also lets you check what containers share and which data survives a restart within the Pod.

Check your understanding

A helper container crashes and restarts. Will a file it wrote to the Pod’s emptyDir disappear?

The same Pod still owns the volume, so the restart leaves its files in place unless application logic removes them. A replacement Pod gets a new emptyDir. Storage that should survive replacement needs a separate lifetime.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu