Try Sailor Cloud - 25% off!

Claim Now
Back to all posts

Kubernetes Pod Lifecycle: From Creation to Termination

Kubernetes Pod Lifecycle: From Creation to Termination

Understanding the pod lifecycle is fundamental to working with Kubernetes. This knowledge is tested in both CKA and CKAD exams and is essential for troubleshooting production issues.

Pod Phases

A pod goes through several phases during its lifecycle:

PhaseDescription
PendingPod accepted but containers not yet running
RunningAt least one container is running
SucceededAll containers terminated successfully
FailedAt least one container terminated with error
UnknownPod state cannot be determined

The Pod Creation Process

  1. API Request: kubectl or controller sends pod spec to API server
  2. Scheduling: Scheduler assigns pod to a node
  3. Kubelet Pickup: Node’s kubelet receives pod specification
  4. Container Creation: Container runtime pulls images and starts containers
  5. Running: Pod enters Running phase
# Watch pod creation in real-time
kubectl get pods -w

# See detailed events
kubectl describe pod my-pod

Init Containers

Init containers run before main containers and must complete successfully:

apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  initContainers:
  - name: init-db
    image: busybox
    command: ['sh', '-c', 'until nc -z db-service 5432; do sleep 2; done']
  containers:
  - name: app
    image: my-app:latest

Container Probes

Liveness Probe

Determines if container is healthy. Restart if unhealthy.

Readiness Probe

Determines if container is ready to receive traffic.

Startup Probe

For slow-starting containers. Disables other probes until success.

containers:
- name: app
  livenessProbe:
    httpGet:
      path: /health
      port: 8080
    initialDelaySeconds: 3
    periodSeconds: 5
  readinessProbe:
    httpGet:
      path: /ready
      port: 8080
    initialDelaySeconds: 5
    periodSeconds: 10

Pod Termination

When a pod is deleted:

  1. Pod marked as Terminating
  2. PreStop hook executed (if defined)
  3. SIGTERM sent to containers
  4. Grace period (default 30s)
  5. SIGKILL if still running
  6. Pod removed from API

Practice Pod Lifecycle

Understanding pod lifecycle is best learned through hands-on practice. At Sailor.sh, practice creating, debugging, and managing pods in real Kubernetes clusters.

Start Free Practice