Troubleshooting kubernetes pod get stuck in Terminating status

Pods in Kubernetes can sometimes get stuck in the “Terminating” status, which means that they are being terminated but have not yet completed the process. This can happen for several reasons:

Containers inside the pod are not terminating

If a container inside the pod is not terminating, it can prevent the pod from being terminated. You can use the command kubectl describe pod to check the container status and logs for more information.

kubectl describe pod-name -n pod-namespace
kubectl logs po-name -n pod-namespace
Volume claims are not being released

Pods may also get stuck in terminating status if the PVCs (persistent volume claims) associated with them are not being released. You can check the PVCs associated with the pod using the command kubectl describe pod and check if they are in “Terminating” status.

Finalizers blocked pod from terminating

check pod definiation or deployment defination yaml in metadta block, to see if there are finalizers defined and delete them.

kubectl -n ${namespace} patch pod ${pod} -p '{"metadata":{"finalizers":null}}'
Networking issues

If there are networking issues in the cluster, it may prevent the pod from being terminated. You can check the pod status and logs for more information.

Delayed termination grace period

Pods have a termination grace period, which is the amount of time the kubelet will wait for the pod to terminate before forcefully killing it. By default, the termination grace period is 30 seconds, but it can be configured using the terminationGracePeriodSeconds field in the pod definition.

To resolve the issue, you can try the following:

  • Forcefully delete the pod using the command
kubectl delete pod --grace-period=0 --force
  • Delete any associated PVCs that are not being released
  • Check for networking issues and resolve them
  • Increase the termination grace period
  • Check the pod and container logs for more information
  • Delete finalizers defined in metadata block

It’s important to be careful when forcefully deleting pods, as it could cause data loss or other issues if the pod is not properly terminated.

Leave a Reply

Your email address will not be published. Required fields are marked *