- Published on
Deleting a Stuck Kubernetes Namespace in "Terminating" State
- Authors
- Name
- Alexander Arana Escobedo
Have you ever encountered a situation where you tried to delete a Kubernetes namespace, but it got stuck in the "Terminating" state, causing frustration? If so, this article is here to help you resolve this annoying issue! 🤓
Start by retrieving the details of the problematic namespace using the following command:
kubectl get namespace <NAMESPACE_NAME> -o json > temp.json
This command saves the namespace details to a file called temp.json.
Open the temp.json file and remove the content inside the spec.finalizers section. It should look something like this:
Now, let's establish a connection to your Kubernetes cluster by running the following command:
kubectl proxy
This command creates a secure connection to your Kubernetes cluster, making it easier to interact with cluster resources using your web browser or API requests from your local machine.
Start a new terminal session, use one of the following commands based on your operating system:
#For windows terminals, don’t forget to start a new terminal session!
curl -k -H "Content-Type: application/json" -X PUT --data-binary "@temp.json" http://127.0.0.1:8001/api/v1/namespaces/<NAMESPACE_NAME>/finalize
#For Linux or Bash, don’t forget to start a new terminal session!
curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json http://127.0.0.1:8001/api/v1/namespaces/<NAMESPACE_NAME>/finalize
This should trigger the deletion process for the namespace.
Once the deletion is complete, don't forget to stop the kubectl proxy by pressing Ctrl + C (in Windows).
I hope this guide helps you out! If you have any questions, don’t hesitate to reach out.
Alexander Arana.E