Kubernetes Pod Lifecycle: From Creation to Termination
Learn the Kubernetes Pod lifecycle from creation and scheduling to startup, readiness, restart behavior, graceful termination and troubleshooting.
Kubernetes Pod Lifecycle: From Creation to Termination
A practical guide to Pod phases, container states, startup, restart behavior, readiness, completion and graceful termination
Introduction
A Kubernetes Pod does not simply start and stop. Its lifecycle is a sequence of events involving the Kubernetes API server, scheduler, kubelet, container runtime and workload controllers. Understanding that sequence makes it much easier to troubleshoot Pending Pods, startup failures, readiness problems, CrashLoopBackOff, failed batch workloads and slow termination.
This article follows a Pod from creation through scheduling and initialization, container startup, normal operation, failure and restart behavior, successful completion and graceful termination.
What Is a Kubernetes Pod?
A Pod is the smallest deployable unit in Kubernetes. It represents one or more containers that are managed together and share network identity and, when configured, storage volumes. Containers inside the same Pod are co-located and share the Pod network namespace.
For long-running applications, users normally create Pods indirectly through controllers such as Deployments, StatefulSets and DaemonSets. Jobs and CronJobs manage Pods for finite or scheduled work.
Pod Lifecycle at a Glance
Pod Phases
Kubernetes exposes a Pod phase as a high-level summary of the Pod lifecycle. It is not a complete representation of every container state or Pod condition.
Important distinction: Pod phase is different from container state. A Pod can have a Running phase while one of its containers is repeatedly failing and restarting.
1. Pod Creation: From Manifest to API Object
The lifecycle starts when a Pod object is submitted to the Kubernetes API, commonly with kubectl or indirectly through a controller.
kubectl apply -f pod.yaml
kubectl get pod lifecycle-demo
The API server validates and persists the accepted object. At this point, the Pod object existing in the API does not mean that its containers are already running.
Example Pod
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
containers:
- name: app
image: nginx:1.29
ports:
- containerPort: 80
2. Scheduling: Selecting a Node
For a normal unscheduled Pod, the Kubernetes scheduler evaluates the Pod requirements and selects a suitable node. Scheduling can be affected by resource requests, node selectors, affinity and anti-affinity, taints and tolerations, topology constraints and other scheduling rules.
Until a suitable node is selected, a Pod commonly remains Pending.
Why a Pod Can Stay Pending
• No node has enough available requested CPU or memory.
• A node selector, affinity rule or topology constraint cannot be satisfied.
• A node taint is not tolerated by the Pod.
• No suitable worker node is Ready.
• Other scheduling constraints prevent placement.
kubectl describe pod lifecycle-demo
kubectl get nodes
kubectl get events --sort-by=.lastTimestamp
3. Kubelet Preparation on the Selected Node
After scheduling, the kubelet on the selected node works to make the Pod specification real on that node. With the container runtime and other node components, it prepares the Pod sandbox and networking, mounts required volumes, pulls images when necessary, and creates the containers.
This is one reason a Pod can remain Pending even after it has been scheduled: scheduling and actual container startup are separate stages.
4. Init Containers Run Before Application Containers
If init containers are defined, they run before application containers. They execute sequentially and each must complete successfully before the next init container starts.
spec:
initContainers:
- name: init-check
image: busybox:1.37
command: ["sh", "-c", "echo initialization complete"]
containers:
- name: app
image: nginx:1.29
Init containers are useful for initialization work such as preparing files or waiting for a prerequisite. If an init container cannot complete successfully, application containers do not proceed normally.
5. Application Container States
Container state is more detailed than Pod phase. Use both when troubleshooting.
6. Startup, Readiness and Liveness Probes
Kubernetes provides startup, readiness and liveness probes for different lifecycle decisions.
containers:
- name: app
image: nginx:1.29
startupProbe:
httpGet:
path: /
port: 80
failureThreshold: 30
periodSeconds: 2
readinessProbe:
httpGet:
path: /
port: 80
periodSeconds: 5
livenessProbe:
httpGet:
path: /
port: 80
periodSeconds: 10
A readiness failure can remove a Pod from eligible Service endpoints while the container remains running. A startup probe can delay liveness and readiness checking until startup succeeds.
7. Running Does Not Mean Ready
A Pod can be Running while the application is still warming up or failing its readiness check. This distinction is fundamental to reliable traffic management. A Service should not send application traffic merely because a process exists; readiness is the signal used to indicate that the workload can accept traffic.
Common Conditions
8. Container Failure and Restart Behavior
A container can terminate while its Pod object remains. Whether it is restarted depends on restartPolicy and the workload type.
Deployments, ReplicaSets, StatefulSets and DaemonSets use Pods with restartPolicy Always. Jobs are designed for finite work and can use Never or OnFailure.
CrashLoopBackOff
CrashLoopBackOff is not a Pod phase. It is a status indication commonly shown when a container repeatedly starts, terminates and is restarted with increasing backoff delays.
kubectl get pod lifecycle-demo
kubectl describe pod lifecycle-demo
kubectl logs lifecycle-demo -c app --previous
The --previous option is especially useful when the current container instance has restarted and the previous instance contains the failure logs.
9. Successful Completion and Failure
Long-running applications are normally expected to continue running. Batch workloads are different: their Pods can finish. A Pod reaches Succeeded when all containers terminate successfully and no further restart is expected. A Pod reaches Failed when all containers have terminated and at least one terminated unsuccessfully, with no further restart expected.
Jobs use this behavior to track finite work. A Deployment instead focuses on maintaining the desired number of application Pods, so an individual failed Pod is normally replaced by its controller.
10. What Happens When a Pod Is Deleted?
Pod deletion is normally graceful. A Pod may be deleted by a user, replaced during a rollout, removed during node maintenance, evicted under resource pressure, or removed by another controller or cleanup process.
When termination begins, Kubernetes records that the Pod is being deleted. The kubelet coordinates container shutdown on the node.
Graceful Termination Sequence
1. A deletion or replacement event causes the Pod to enter termination.
2. The kubelet begins shutdown processing on the node.
3. A preStop lifecycle hook is run when one is configured and applicable.
4. The container runtime is asked to stop the container processes, allowing the application to handle termination.
5. The configured termination grace period counts down.
6. If a container has not exited when the grace period expires, Kubernetes can forcefully terminate it.
7. The Pod object is eventually removed after termination processing and any applicable finalizers are complete.
terminationGracePeriodSeconds
The Pod specification controls the graceful shutdown window with terminationGracePeriodSeconds. The default is 30 seconds when the field is not otherwise configured.
spec:
terminationGracePeriodSeconds: 60
containers:
- name: app
image: nginx:1.29
The correct value depends on the application. A server processing in-flight requests may need more time than a short-lived process.
preStop Hooks
A preStop hook can perform a short shutdown action before the container process is stopped. It should be reliable and should complement, not replace, proper signal handling in the application.
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "echo preparing shutdown"]
11. Deletion, Eviction and Restart Are Different
12. What Happens to a Deployment Pod?
A Deployment normally manages a ReplicaSet, which maintains the desired number of Pods. If a managed Pod disappears, the controller creates a replacement Pod. The replacement is a new Pod object with a new identity; Kubernetes does not restore the deleted Pod object.
This gives an important troubleshooting rule: a container restart keeps the same Pod, while controller replacement creates a new Pod.
13. Troubleshooting the Pod Lifecycle
Pod is Pending
• Run kubectl describe pod and inspect Events.
• Check resource requests and node capacity.
• Check selectors, affinity, topology rules, taints and tolerations.
• Confirm that suitable nodes are Ready.
Pod is Running but Not Ready
• Inspect readinessProbe configuration.
• Check application logs and dependencies.
• Verify probe path, port or command.
• Inspect Pod conditions and Service endpoints.
Pod is in CrashLoopBackOff
• Read current and previous container logs.
• Inspect termination reason and exit code.
• Check environment variables, mounted configuration and secrets.
• Review liveness and startup probes.
• Verify command and arguments.
Pod is Stuck Terminating
• Inspect deletionTimestamp and events.
• Review preStop hooks and terminationGracePeriodSeconds.
• Check application signal handling.
• Inspect finalizers before considering forced cleanup.
14. Useful kubectl Commands
15. Common Mistakes
• Treating Running as equivalent to Ready.
• Calling CrashLoopBackOff a Pod phase.
• Assuming a Deployment restarts the same deleted Pod object.
• Using liveness probes to solve readiness problems.
• Using aggressive liveness settings for slow-starting applications.
• Ignoring init container failures.
• Assuming Pod deletion is always immediate.
• Using long or unreliable preStop hooks.
• Ignoring application-level signal handling.
16. Production Best Practices
• Use appropriate controllers instead of manually managing long-running Pods.
• Set realistic CPU and memory requests and limits.
• Use readiness probes to protect traffic routing.
• Use liveness probes only when a restart is an appropriate recovery action.
• Use startup probes for genuinely slow-starting applications.
• Design applications to handle termination signals cleanly.
• Set termination grace periods based on measured shutdown behavior.
• Keep preStop hooks short and dependable.
• Monitor restart counts, readiness, termination reasons and events.
• Test rollout, node drain and shutdown behavior before production incidents occur.
17. Real-World Scenario: HTTP API During a Deployment
Imagine an HTTP API managed by a Deployment. A new Pod starts but needs time to load configuration and warm caches. Its container may be Running while readiness remains false, so it is not treated as ready for Service traffic. Once readiness succeeds, the Pod becomes eligible. During rollout, an old Pod can be selected for termination; graceful shutdown gives it time to finish in-flight work and close resources.
The key lesson is that process availability, traffic readiness and Pod termination are different lifecycle concerns that must be designed together.
18. Hands-On Lab
Step 1: Create a Pod
cat > lifecycle-demo.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
terminationGracePeriodSeconds: 20
containers:
- name: app
image: nginx:1.29
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
periodSeconds: 5
EOF
kubectl apply -f lifecycle-demo.yaml
Step 2: Watch Lifecycle Changes
kubectl get pod lifecycle-demo -w
Step 3: Inspect State
kubectl describe pod lifecycle-demo
kubectl get pod lifecycle-demo -o yaml
Step 4: Observe Readiness
Temporarily configure the readiness probe to check an invalid endpoint. Observe that the container can remain Running while the Pod is not Ready. Restore the valid probe and observe readiness return.
Step 5: Observe Termination
kubectl delete pod lifecycle-demo
kubectl get pod lifecycle-demo -w
19. Kubernetes Pod Lifecycle Interview Questions
1. What are the five Pod phases?
Answer: Pending, Running, Succeeded, Failed and Unknown.
2. Is CrashLoopBackOff a Pod phase?
Answer: No. It is a status indication associated with repeated container restart attempts and backoff.
3. What is the difference between Running and Ready?
Answer: Running is a high-level Pod phase; Ready indicates that the Pod is considered ready to serve traffic.
4. What are the three container states?
Answer: Waiting, Running and Terminated.
5. What is an init container?
Answer: A container that performs initialization and must complete before application containers proceed.
6. What does a readiness probe do?
Answer: It indicates whether the application is ready to receive traffic; it does not restart the container.
7. What does a liveness probe do?
Answer: It detects a running container that is no longer healthy and can trigger a restart.
8. Why use a startup probe?
Answer: To give slow-starting applications time to initialize before liveness and readiness checks take effect.
9. What happens when a Deployment-managed Pod is deleted?
Answer: The controller works to restore the desired number of Pods, normally by creating a replacement Pod.
10. What is terminationGracePeriodSeconds?
Answer: The graceful shutdown period available to a terminating Pod before forceful termination may occur.
11. What is the difference between container restart and Pod replacement?
Answer: A restart keeps the same Pod object; replacement creates a new Pod object.
20. Pod Lifecycle Checklist
• Explain Pod phase, Pod conditions and container state.
• Explain what happens between API submission and container startup.
• Diagnose a Pending Pod.
• Explain why Running does not necessarily mean Ready.
• Explain CrashLoopBackOff accurately.
• Explain init container execution.
• Explain restartPolicy behavior.
• Explain graceful termination and terminationGracePeriodSeconds.
• Troubleshoot a Pod stuck in Terminating.
• Explain why a controller creates a replacement Pod instead of restoring a deleted Pod object.
Summary
The Kubernetes Pod lifecycle is a set of coordinated control-plane and node-level actions. A Pod is created through the API, scheduled when necessary, prepared by the kubelet, initialized, started and monitored. Its containers can be Waiting, Running or Terminated, while the Pod exposes higher-level phases and conditions.
When containers fail, restart behavior depends on restartPolicy and the workload. When a Pod is deleted or replaced, Kubernetes normally provides a graceful termination window so applications can finish work and exit cleanly. Understanding these distinctions is fundamental to production Kubernetes troubleshooting.
Related Topics
• Kubernetes Pod Explained: Architecture, Lifecycle, States and Restart Behavior
• Kubernetes ReplicaSet Explained: How Kubernetes Maintains Pod Availability
• Kubernetes Deployment Explained: Rolling Updates, Rollbacks and Revision History
• Kubernetes StatefulSet Explained: Stable Identity, Storage and Ordered Deployment
• Kubernetes DaemonSet Explained: Running Pods on Every Kubernetes Node
• Kubernetes Job and CronJob Explained: Batch and Scheduled Workloads
• Kubernetes Deployment Strategies: Rolling, Recreate, Blue-Green and Canary
• Kubernetes Services and Service Discovery
• Kubernetes Scheduling: Requests, Limits, Affinity, Taints and Tolerations
Official Kubernetes References
• https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/
• https://kubernetes.io/docs/concepts/workloads/pods/
• https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
• https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
• https://kubernetes.io/docs/concepts/workloads/controllers/job/
• https://kubernetes.io/docs/concepts/workloads/controllers/deployment/