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:
| Phase | Description |
|---|---|
| Pending | Pod accepted but containers not yet running |
| Running | At least one container is running |
| Succeeded | All containers terminated successfully |
| Failed | At least one container terminated with error |
| Unknown | Pod state cannot be determined |
The Pod Creation Process
- API Request: kubectl or controller sends pod spec to API server
- Scheduling: Scheduler assigns pod to a node
- Kubelet Pickup: Node’s kubelet receives pod specification
- Container Creation: Container runtime pulls images and starts containers
- Running: Pod enters Running phase
# Watch pod creation in real-time
kubectl get pods -w
# See detailed events
kubectl describe pod my-podInit 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:latestContainer 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: 10Pod Termination
When a pod is deleted:
- Pod marked as Terminating
- PreStop hook executed (if defined)
- SIGTERM sent to containers
- Grace period (default 30s)
- SIGKILL if still running
- 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.