When deleting a namespace, the delete operation is interrupted when it is not completely deleted, and the namespace is in the terminating state. One solution is to delete again with the --force option after the command, e.g.

 1  kubectl delete ns --force 

But it often doesn’t work, so you need to use the interface to delete the namespace.

First, export the namespace information for the terminating state to a json file.

 1  kubectl get ns -o json > temp.json 

This will result in a tmp.json file in the current directory. Edit this file and set the value of finalizers to null (to an empty array).

Next, open the proxy.

 1  kubectl proxy 

Open a new command line terminal and call the following interface at the location of the temp.json file.

 1  curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json http://127.0.0.1:8001/api/v1/namespaces//finalize 

where <terminating-namespace> is changed to the name of the namespace of the terminating state that needs to be deleted.

Finally, verify that.

 1  kubectl get ns 

There will no longer be a namespace for this terminating state.