Appearance

The Pod lifecycle

Separate Pod identity, container states, restart policy, and shared resources.

What you will understand

  • Explain what a Pod shares and what it does not
  • Read phase, conditions, and container termination state
  • Predict restart behavior without inventing Pod migration

Builds on: kubectl and your cluster context

Mental model: one scheduling and lifecycle unit

A Pod groups one or more containers that need a shared placement and lifecycle boundary. Kubernetes schedules the Pod to one node; its ordinary containers do not independently land on different workers. Most application replicas use one main container per Pod. Put tightly cooperating helpers together when they need Pod-local sharing, not simply because they belong to the same business application. Independent frontends and databases usually need independent replica counts and release lifecycles.

Containers in a Pod share a network namespace, including the Pod IP, interfaces, and port space. They can reach each other over localhost. Two containers cannot normally bind the same address and port at once. They do not automatically share their root filesystems. To exchange files, declare a volume and mount it in each container at intentional paths. Process namespace sharing is not implied by ordinary Pod networking; it is a separate setting when required.

An emptyDir is created for a Pod’s lifetime. It can preserve files across a container restart in that same Pod, while files written solely into a container’s writable layer are lost when that container is recreated. Deleting and replacing the Pod removes its emptyDir. Persistent storage is a later topic; naming an emptyDir data does not make it durable.

What containers in a Pod share

Contrast shared networking and explicitly mounted storage with separate root filesystems.

Cluster viewStep 1 of 3
One Pod, one placementBoth containers belong to one Pod scheduled on one worker. They are not independently scheduled replicas.. Worker node-a, ready. Pod UID P, active. App container, ready. Helper container, readyWorker node-a
Worker node-aReady
Pod UID P
Pod UID PIn focus
App container
App containerReady
Helper container
Helper containerReady
Worker node-aReady
Pod UID PIn focus
App containerReady
Helper containerReady
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: two listeners compete
One Pod, one placement

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

Read the complete visual sequence
  1. One Pod, one placement

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

  2. Share the network namespace

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

  3. Mount storage explicitly

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

Failure: two listeners compete

Failure: two listeners compete

  1. Both containers choose port 8080

    The app already binds all local interfaces on port 8080. The helper attempts the same address and TCP port.

  2. The helper bind fails

    Separate images do not create separate network namespaces inside this Pod. The helper may exit with address-in-use evidence.

  3. Choose distinct ports

    Configure the helper on 9090 or use another explicit local IPC design. Documenting different containerPort fields is insufficient unless the processes bind accordingly.

About this model

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

Walkthrough: run a finite executable

Save this as lifecycle-demo.yaml and apply it in a disposable namespace. The command emits one line and exits deliberately with code 7. This is an expected training failure, not an image pull failure.

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 terminated state should include exit code 7, and the Pod should eventually be Failed. The failure occurs after successful execution began, so application output is available. If the image cannot be downloaded, the process never starts and those expected logs will not exist.

A container can be Waiting, Running, or Terminated. A Pod’s phase is a coarse summary: Pending includes scheduling and preparation, Running describes a started/bound Pod with running or restarting activity, Succeeded indicates successful completion without further restarts, Failed indicates terminal failure, and Unknown indicates unavailable state information. Conditions such as PodScheduled and Ready answer more specific questions. CrashLoopBackOff and Terminating can appear in kubectl’s display column without being Pod phase values.

Restart a container, replace a Pod

Compare kubelet restart policy with controller-created replacement identity.

Lifecycle viewStep 1 of 3
The executable terminatesThe app exits with code 7. Its container state becomes Terminated while the Pod identity and node binding still exist.. Pod UID P on node-a, active. Terminated: exit 7, failed. Kubelet node-a, activePod UID P on node-a
Pod UID P on node-aIn focus
Terminated: exit 7
Terminated: exit 7Failed
Kubelet node-a
Kubelet node-aIn focus
Pod UID P on node-aIn focus
Terminated: exit 7Failed
Kubelet node-aIn focus
Animation controls
Speed
0.5×
1×
2×
Explore a scenario
Normal behavior
Failure: Never means no container retry
The executable terminates

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

Read the complete visual sequence
  1. The executable terminates

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

  2. OnFailure retries locally

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

  3. A deleted Pod requires replacement

    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.

Failure: Never means no container retry

Failure: Never means no container retry

  1. A finite command exits unsuccessfully

    The worker command prints its message and exits 7 under restartPolicy Never.

  2. The Pod becomes terminally failed

    For this one-container example, the Pod reaches Failed. The kubelet does not restart that app container.

  3. Use evidence before rerunning

    Inspect the logs and termination state, then correct the command or use a workload appropriate to repeatable tasks.

About this model

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.

Practice: compare restart policies

For a new named Pod, change the policy to OnFailure while retaining exit code 7. Expect the kubelet to attempt container restarts, with backoff for repeated failures. Change the executable to exit 0: OnFailure does not restart a successful completion. With Always, ordinary app containers restart after either successful or unsuccessful exit. These examples use the basic Pod-level rules without per-container restart overrides; restartable init sidecars have their own behavior introduced next. Deployment and ReplicaSet Pod templates permit only Pod-level Always, so perform the Never and OnFailure comparisons with standalone Pods. Do not assume that changing a policy on an existing Pod is an allowed in-place update; use a new disposable Pod name for comparisons.

Record the Pod UID and node name as restart counts rise. A container restart is local supervision inside the same Pod identity. If that Pod is deleted or lost, a workload controller can create a new Pod with a new UID. The scheduler binds that new object. Kubernetes does not take the original Pod UID and migrate it to another worker.

Pitfalls

A Pod can be Running while its application repeatedly crashes. Ready is a separate condition, and the application needs meaningful readiness checks to express actual usability. A sidecar that stays alive can also complicate a superficial “some process is running” interpretation. Read per-container state rather than only the top-level display.

Restarting is not a repair for every failure. A bad argument, missing configuration key, or unavailable dependency can reproduce immediately after each restart. Investigate termination reason, exit code, logs, and recent configuration changes before increasing retries or adding aggressive liveness checks.

Check your understanding

A container restarts in its Pod after writing to both /tmp and a mounted emptyDir. Which data should you expect to retain?

Data written into the mounted emptyDir can remain because that volume follows the Pod lifetime. Data written only into the replaced container’s writable filesystem does not. If the entire Pod is replaced, its emptyDir is also new. The path string is not enough to predict durability; identify the mounted storage and the lifecycle boundary that owns it.

Use the module lab to compare finite execution, local restart, and controller replacement. Next, put initialization and tightly coupled helpers into this shared boundary deliberately.

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.