Kubectl: Force Delete Namespace Stuck in Terminating

Kubectl Force Delete Namespace Stuck in Terminating

In this post, we will show you how to use Kubectl command to force delete namespace stuck in terminating state for a long time. You may be seeing this issue when pods are in terminating state for a long time, but there wont be no response. It could be for various reason, like some resources might have gone to nonresponsive mode.

If you are interested in learning, Request you to go through the below recommended tutorial.

Table of Contents

  1. Understanding Terminating State in Kubernetes

  2. Checking Namespace Status

  3. Identifing Root Cause

  4. Force Deleting Namespace

Understanding Terminating State in Kubernetes:

In kubernetes cluster, if we decided to delete a namespace in kubernetes. We will use kubectl delete ns command to delete the kubernetes namespace. On some cases, the namespace will enter into terminating in state when you check kubernetes namespace status.

Even Kubernetes will gracefully terminate all resources associated in kubernetes namespace. Because Kubernetes namespace is a isolated space.

Checking Namespace Status:

First, we need to check the kubernetes namespace status. Use kubectl get ns command as below. 
kubectl get namespaces

or

kubectl get ns

Above kubectl get ns command will show you all the list of kubernetes namespace available in your kubernetes cluster. Find your problematic namespace that is in terminating state.

Identifying Root Cause:

Next step is to identify the root cause of kubernetes namespace, why it is entered into terminating state. Use kubectl describe command to get the complete details about the namespace.
kubectl describe namespace <namespace-name>

Above kubectl describe command will provide you the complete information about your namespace, in kubernetes. This will include specifications and events. So identify any errors or finalizers that might be causing the termination to hang state.

Force Deleting Namespace:

If you didnt find any valid reason for the reason why namespace went into terminating state, then we have to delete the namespace forcefully.

We have an option called --grace-period=0 , that can be used along with kubectl delete namespace command to delete the namespace gracefully.
kubectl delete namespace <namespace-name> --grace-period=0 --force

Where, replace <namespace-name> with your problematic namespace name. This command will completely remove your namespace from the kubernetes clsuter gracefully.

That's it for this post. Keep practicing and have fun. Leave your comments if any.

Related Searches and Questions asked:

  • Kubectl: Get Pod Containers
  • Helm Upgrade: Update Chart Values with Examples
  • Troubleshooting Kubernetes Node Disk Pressure
  • Kubectl Dry Run Client and Server Command Examples

  • Post a Comment

    0 Comments