Kubernetes pod lifecycle: Phases, states and transitions explained

Understand the complete Kubernetes pod lifecycle from creation through scheduling to termination. Covers pod phases, liveness and readiness probes, init containers, hooks, and restart policies.

9 lessons · 27 min · Intermediate

3 minutes reading time

Written by

Civo Team
Civo Team

Marketing Team at Civo

When you create a pod, it does not immediately start running. It moves through a series of phases as Kubernetes schedules it, pulls the container image, starts the container, and eventually terminates it. Understanding these phases helps you diagnose problems and reason about pod behaviour.

Pod phases at a glance

pod-issues-diagnostic
PhaseWhat it means

Pending

The pod has been accepted by Kubernetes and stored in etcd. A node has not yet been assigned, or the node has been assigned but the image is still being pulled.

ContainerCreating

A node has been assigned and the image has been pulled. The container runtime is creating the container.

Running

At least one container is running. The pod has been bound to a node and all containers have been started.

Succeeded

All containers in the pod have exited with status code 0. The pod has completed its work and will not be restarted.

Failed

At least one container exited with a non-zero status code or was terminated by the system.

Unknown

The state of the pod cannot be determined. This usually means the node the pod was running on has lost communication with the API server.

What happens when you create a pod

When you run kubectl apply -f pod.yaml or kubectl create -f pod.yaml, the following sequence happens:

kubectl apply -f pod.yaml
  1. kubectl converts the YAML to JSON and sends it to the API server
  2. The API server authenticates the request using your kubeconfig credentials
  3. The API server checks whether the user is authorised to create a pod
  4. Admission controllers run any cluster-level policy checks
  5. The pod object is persisted to etcd and enters Pending state
  6. The scheduler watches for unscheduled pods, finds the best available node based on resource requirements and constraints, and updates the pod spec with the node name
  7. The updated pod object is stored in etcd
  8. The API server notifies the kubelet on the selected node
  9. The kubelet instructs the container runtime to pull the image from the registry
  10. The CNI plugin assigns an IP address to the pod and reports it back to the API server
  11. The pod moves to ContainerCreating then Running once the container starts

Watch the phase transitions in real time:

kubectl get pods -w

Observing pod state

Check the current state of all pods:

kubectl get pods

Expected output:

NAME READY STATUS RESTARTS AGE
sample-pod 1/1 Running 0 2m

Get detailed information including events:

kubectl describe pod sample-pod

The Events section at the bottom shows each step: node assignment, image pull, container creation, and start. When a pod is stuck in any state, the Events section usually explains why.

Restart policies

The restart policy controls what Kubernetes does when a container inside a pod exits. Set it in the pod spec under spec.restartPolicy.

PolicyBehaviour

Always

Restart the container whenever it exits, regardless of exit code. This is the default. Use for long-running services.

OnFailure

Restart the container only if it exits with a non-zero exit code. Use for batch jobs that should retry on failure but not restart after successful completion.

Never

Never restart the container. Use for one-off tasks where you want to inspect the result regardless of outcome.

Example pod with OnFailure restart policy:

apiVersion: v1
kind: Pod
metadata:
name: batch-job
spec:
restartPolicy: OnFailure
containers:
- name: worker
image: busybox
command: ["sh", "-c", "echo processing && exit 0"]

CrashLoopBackOff

If a container crashes and restarts too many times in quick succession, Kubernetes puts it into CrashLoopBackOff. This is not a phase but a status that indicates Kubernetes is backing off restart attempts with increasing delays to prevent overwhelming the system.

kubectl get pods

Example output showing CrashLoopBackOff:

NAME READY STATUS RESTARTS AGE
broken-pod 0/1 CrashLoopBackOff 5 3m

Diagnose the cause:

kubectl logs broken-pod

If the container has already restarted, check the previous container's logs:

kubectl logs broken-pod --previous

Hooks

Kubernetes supports two lifecycle hooks that run commands at specific points in the container lifecycle.

PostStart runs immediately after the container starts. It runs concurrently with the container's main process. If it fails, the container is killed.

PreStop runs immediately before the container receives a SIGTERM signal. Use it to gracefully drain connections or flush in-flight requests before shutdown. Without it, a rolling update may drop in-flight requests.

spec:
containers:
- name: nginx
image: nginx
lifecycle:
postStart:
exec:
command: ["sh", "-c", "echo container started"]
preStop:
exec:
command: ["sh", "-c", "nginx -s quit && sleep 5"]

Init containers and probes

Init containers run to completion before the main container starts. They are useful for pre-conditions like waiting for a dependency to be ready. See Kubernetes init containers for working examples.

Liveness and readiness probes tell Kubernetes whether a container is healthy and ready to receive traffic. A failed liveness probe causes the container to be restarted. A failed readiness probe removes the pod from service endpoints without restarting it. See Kubernetes container probes for a full guide.

Civo Team
Civo Team

Marketing Team at Civo

Civo is the Sovereign Cloud and AI platform designed to help developers and enterprises build without limits. We bridge the gap between the openness of the public cloud and the rigorous security of private environments, delivering full cloud parity across every deployment. As a team, we are dedicated to providing scalable compute, lightning-fast Kubernetes, and managed services that are ready in minutes. Through CivoStack Enterprise and our FlexCore appliance, we empower organizations to maintain total data sovereignty on their own hardware.

Our mission is to make the cloud faster, simpler, and fairer. By providing enterprise-grade NVIDIA GPUs and streamlined model management, we ensure that high-performance AI and machine learning are accessible to everyone. Built for transparency and performance, the Civo Team is here to give you total control over your infrastructure, your data, and your spend.

View author profile