Pods stuck in Terminating status
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When working with Kubernetes, one of the common issues operators and developers might encounter is Pods being stuck in the "Terminating" state. This situation often arises during the management or scaling down of Kubernetes applications and can be due to several reasons rooted in both the Kubernetes architecture and the specific application behavior. Understanding and troubleshooting these issues is crucial for maintaining the stability and reliability of applications deployed on Kubernetes.
Technical Background
In Kubernetes, a Pod represents one or more containers. These containers are the smallest deployable units of computing that can be created and managed in Kubernetes. When a Pod is no longer needed, it is scheduled for deletion, entering the Terminating state. During this state, Kubernetes performs a series of operations to gracefully shut down all the Pod's containers and release any associated resources.
The lifecycle of a Pod is managed by the Kubernetes Control Plane, which orders deletions via the Kubernetes API server. Upon receiving a delete request, the cluster attempts to clean up resources associated with the Pod. Several factors can result in Pods being stuck in the Terminating state, and understanding these factors is essential for resolving the issue.
Common Causes of Stuck Pods
Below are some common causes for Pods getting stuck in the Terminating state, along with technical explanations of each:
- Finalizers:
- Finalizers are used to ensure that specific cleanup actions occur before the deletion of a Kubernetes object. If a finalizer is not removed, the Pod will remain in the Terminating state.
- Solution: Inspect the Pod's metadata to check for finalizers. You can use the
kubectl patchcommand to remove problematic finalizers.
- Grace Period:
- By default, Kubernetes provides a 30-second grace period before forcefully deleting containers. This allows applications to clean up tasks. If processes do not terminate within this period, the Pod may remain stuck.
- Solution: Manually delete the Pod using
kubectl delete pod <pod-name> --grace-period=0 --forceto override the graceful shutdown.
- Network and Storage Dependencies:
- Pods might be waiting for network or storage resources to detach or decommission. If these operations don't complete successfully, the Pod can be stuck.
- Solution: Check and ensure all associated network and storage resources are orderly released.
- Pending Node Issues:
- If the node hosting the Pod is not responding or has network issues, the Pod could be stuck.
- Solution: Perform a
kubectl get node <node-name>to verify node status and address any issues accordingly.
- Application-Specific Cleanup:
- Some applications have custom scripts or procedures to follow during termination that may not complete successfully.
- Solution: Review application logs and code to ensure all shutdown procedures are correctly implemented and observe the logs for anomalies during termination.
Troubleshooting Steps
When addressing Pods in the Terminating state, consider the following steps as part of your troubleshooting regimen:
1. Check Pod Status and Logs
Inspect the Pod status and review logs to gather initial troubleshooting data:
2. Examine Finalizers
Check for and clean up any finalizers that may be preventing deletion:
3. Force Deletion
Forcefully terminate the Pod if it's safe to do so:
4. Investigate Node and Resource Status
Ensure the node is in a healthy state and check resource bindings:
Summary Table
| Issue | Description | Solution |
| Finalizers | Objects preventing deletion until custom resources are cleaned up. | Inspect finalizers and remove faulty ones using kubectl patch. |
| Grace Period Exceeding | Default 30-second period for graceful shutdown exceeded without container exit. | Override with kubectl delete pod <pod-name> --grace-period=0 --force. |
| Network/Storage Dependency | Waiting for network or storage resources deallocation | Verify all resource detachments are successful and complete. |
| Pending Node Issues | Non-responsive nodes can leave pods in terminating state. | Check node health and network status with kubectl get node. |
| Application-Specific Cleanup | Custom shutdown procedures in applications not completing correctly. | Investigate application logs and code to ensure proper handling of termination signals. |
Additional Considerations
- API Server and Controller Manager: Ensure that the Kubernetes API server and controller manager are running healthy, as they govern the deletion and cleanup processes.
- Cluster Configuration: Review the cluster’s event logs for unusual activities or misconfigurations that might affect Pod deletion.
Understanding and resolving issues with Pods stuck in the Terminating state requires a comprehensive approach, examining not only Kubernetes itself but also the application lifecycle and interaction with underlying resources. By following structured troubleshooting steps, leveraging Kubernetes tools, and maintaining insights into application behavior, one can ensure smooth operation and rapid resolution of these issues.
Related reading
- PostgreSQL bitnami Helm Chart does not update the user password
- Presto with Kubernetes
- Prevent ArgoCD from syncing a single ressource
- Prevent inter-namespace communication in Kubernetes
- Pre pulling docker images in AMI to reduce node and pod fresh start time slows down it's execution when using nvidia-docker with GPU enabled pods
- Pre pulling docker images in AMI to reduce node and pod fresh start time slows down it's execution when using nvidia-docker with GPU enabled pods
- Pointer is missing a nullability type specifier
- Pool.apply_async nested function is not executed

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.