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.

kubectl delete ns <terminating-namespace> --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.

kubectl get ns <terminating-namespace> -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.

kubectl proxy

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

curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json<terminating-namespace>/finalize

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

Finally, verify that.

kubectl get ns

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