Kubernetes Pod Lifecycle and States Explained
Understand the Kubernetes pod lifecycle from Pending to Terminated. Covers pod phases, container states, restart policies, graceful shutdown, and preStop hooks.
π‘ Quick Answer: Understand the Kubernetes pod lifecycle from Pending to Terminated. Covers pod phases, container states, restart policies, graceful shutdown, and preStop hooks.
The Problem
This is one of the most searched Kubernetes topics. Having a comprehensive, well-structured guide helps both beginners and experienced users quickly find what they need.
The Solution
Pod Phases
| Phase | Description |
|---|---|
| Pending | Pod accepted, waiting for scheduling or image pull |
| Running | At least one container is running |
| Succeeded | All containers exited with code 0 |
| Failed | All containers terminated, at least one with non-zero exit |
| Unknown | Node communication lost |
Container States
# Check container state
kubectl get pod <name> -o jsonpath='{.status.containerStatuses[0].state}'
# States: Waiting, Running, Terminated
# Waiting reasons: ContainerCreating, CrashLoopBackOff, ImagePullBackOff, PodInitializing
# Terminated reasons: Completed, Error, OOMKilledGraceful Shutdown
apiVersion: v1
kind: Pod
spec:
terminationGracePeriodSeconds: 60 # Default: 30
containers:
- name: app
image: my-app:v1
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 5 && /app/shutdown.sh"]
# preStop runs BEFORE SIGTERM is sentShutdown sequence:
- Pod marked for deletion
- Removed from Service endpoints (no new traffic)
preStophook runsSIGTERMsent to container- Wait
terminationGracePeriodSeconds SIGKILLif still running
Restart Policies
| Policy | Behavior | Use Case |
|---|---|---|
Always | Restart on any exit (default) | Deployments, StatefulSets |
OnFailure | Restart only on non-zero exit | Jobs |
Never | Never restart | Jobs (debug with logs) |
Init β Sidecar β Main Container Ordering
graph LR
A[Pod Created] --> B[Init Container 1]
B --> C[Init Container 2]
C --> D[Sidecar starts]
D --> E[Main Container starts]
E --> F[Running]
F -->|Termination| G[preStop hook]
G --> H[SIGTERM]
H --> I[Grace period]
I --> J[SIGKILL if needed]Frequently Asked Questions
Why is my pod stuck in Pending?
Common reasons: insufficient CPU/memory on nodes, no nodes match nodeSelector/affinity, PVC not bound, taints without tolerations. Run kubectl describe pod and check the Events section.
What is the difference between pod phase and container state?
Pod phase is the overall pod status. Container state is per-container. A pod can be Running while one container is in CrashLoopBackOff (if there are other running containers).
Best Practices
- Start simple β use the basic form first, add complexity as needed
- Be consistent β follow naming conventions across your cluster
- Document your choices β add annotations explaining why, not just what
- Monitor and iterate β review configurations regularly
Key Takeaways
- This is fundamental Kubernetes knowledge every engineer needs
- Start with the simplest approach that solves your problem
- Use
kubectl explainandkubectl describewhen unsure - Practice in a test cluster before applying to production

Recommended
Kubernetes Recipes β The Complete Book100+ production-ready patterns with detailed explanations, best practices, and copy-paste YAML. Everything in one place.
Get the Book βLearn by Doing
CopyPasteLearn β Hands-on Cloud & DevOps CoursesMaster Kubernetes, Ansible, Terraform, and MLOps with interactive, copy-paste-run lessons. Start free.
Browse Courses βπ Deepen Your Skills β Hands-on Courses
Courses by CopyPasteLearn.com β Learn IT by Doing
