The Kubernetes Pod Lifecycle
Introduction¶
When you kubectl apply a Deployment, a chain of controllers and the kubelet
turn that spec into running processes. Knowing the sequence tells you where a
stuck pod is stuck.
Creation sequence¶
- API server validates and stores the Pod object (created by the ReplicaSet controller from your Deployment).
- Scheduler watches for pods with no
nodeName, picks a node based on resource requests, affinity, taints/tolerations, and writesnodeNameback. - kubelet on that node sees the pod, and:
- pulls images (respecting
imagePullPolicy) - runs init containers sequentially, each to completion - creates the pause/sandbox container (the shared network namespace) - starts app containers - runspostStarthooks, then startup → readiness → liveness probes - Pod becomes Ready when all containers are ready and any readiness gates pass; the endpoints controller adds it to Service endpoints.
Phase vs container state¶
Pod phase (.status.phase): Pending → Running → Succeeded/Failed
(or Unknown). Coarse.
Container state (.status.containerStatuses[].state): Waiting (with a
reason like ContainerCreating, ImagePullBackOff, CrashLoopBackOff),
Running, or Terminated (with exit code and reason). This is where the useful
detail is.
kubectl get pod mypod -o wide
kubectl describe pod mypod # Events at the bottom = the story
kubectl get pod mypod -o jsonpath='{.status.containerStatuses[*].state}'
Init containers¶
Run in order, each must exit 0 before the next starts, all before app containers. Use for: waiting on a dependency, running migrations, fetching config, setting kernel params via a privileged init.
A failing init container puts the pod in Init:Error / Init:CrashLoopBackOff
and the app never starts.
Probes¶
- startup — disables the other two until it passes once. For slow-booting apps; prevents liveness from killing them during startup.
- readiness — gates Service traffic. Failing readiness removes the pod from endpoints but does not restart it.
- liveness — failing it restarts the container.
Misconfigured liveness is a top cause of self-inflicted CrashLoopBackOff — see Debugging CrashLoopBackOff.
Termination¶
kubectl delete pod / a rollout / a scale-down triggers:
- Pod marked
Terminating, removed from Service endpoints immediately. preStophook runs (if defined).SIGTERMsent to PID 1 in each container.- Kubernetes waits up to
terminationGracePeriodSeconds(default 30). SIGKILLif still running.
spec:
terminationGracePeriodSeconds: 60
containers:
- name: app
lifecycle:
preStop:
exec:
command: ["sh", "-c", "sleep 5"] # let load balancers notice we're gone
The preStop: sleep 5 pattern buys time for the endpoint removal to propagate
through kube-proxy / the ingress before your app stops accepting connections —
avoids dropped requests during a rollout.
Your app must handle SIGTERM: stop accepting new work, finish in-flight
requests, exit. If PID 1 is a shell script that doesn't forward signals, SIGTERM
is swallowed and every shutdown takes the full grace period then SIGKILL. Use an
init like tini, or exec the real process.
Verification and troubleshooting¶
kubectl describe pod mypod # Events
kubectl logs mypod -c app --previous # logs from the crashed instance
kubectl get events --sort-by=.lastTimestamp -n myns
- Stuck
Pending— scheduler can't place it: insufficient CPU/memory on any node, unsatisfied affinity, a taint with no toleration, or no PV available for a PVC.describesays which. - Stuck
ContainerCreating— image pull, a CNI failure, a failingvolumeMount(secret/configmap doesn't exist), or the node's out of IPs. Init:0/2— first init container hasn't completed.kubectl logs mypod -c <init-name>.- Pod restarts cleanly but drops traffic during rollout — no
preStopdelay, or app doesn't drain on SIGTERM. - Shutdown always takes 30s — SIGTERM not reaching/handled by PID 1.
Terminatingforever — a finalizer is stuck, or the node is gone.kubectl delete pod --grace-period=0 --forceas a last resort.
Related tools and reading¶
- On-site: YAML validator, Base64 decoder.
- Related posts: Debugging CrashLoopBackOff, Liveness, readiness, and startup probes.
Stuck on something this site can't fix?Reach out to Prabath directly on LinkedIn.More in Docker & Kubernetes
StatefulSets Explained
StatefulSets give pods sticky names, sticky storage, and ordered operations — what databases and clustered apps need. Here's how each guarantee works.
October 24, 2026Persistent Volumes and Claims, Explained
PVC is a request, PV is the fulfilled storage, StorageClass is the factory. Most 'Pending PVC' problems are an access-mode or provisioner mismatch.
October 24, 2026Kubernetes Jobs and CronJobs
A Job runs pods until they succeed; a CronJob creates Jobs on a schedule. Here's parallelism, retry limits, the missed-schedule trap, and history cleanup.
October 24, 2026