6

Kubectl: Force Delete Namespace Stuck In Terminating

 1 year ago
source link: https://www.shellhacks.com/kubectl-force-delete-namespace-stuck-in-terminating/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Kubectl: Force Delete Namespace Stuck In Terminating

Sometimes a deletion of a Namespace in Kubernetes gets hung up and the kubectl delete namespace command never completes.

Such Namespaces get stuck in a Terminating state but can be manually deleted using a Kubernetes API.

This note shows how to force delete the Terminating Namespaces in Kubernetes using the kubectl command.

Force Delete Terminating Namespace in Kubernetes

List the Namespaces that are stuck in the Terminating state:

$ kubectl get ns
NAME                 STATUS          AGE
<namespaceName>      Terminating     10d

Create a temporary JSON file representing the Terminating Namespace:

$ kubectl get ns <namespaceName> -o json > tmp.json

Edit your tmp.json file:

$ vi tmp.json

Remove any values from the spec.finalizers field:

…
    "spec": {
        "finalizers": []
    },
…

It should look like as follows:

kubectl-delete-namespace-spec-finalizers.png

Save the file and start an HTTP proxy to access the Kubernetes API:

$ kubectl proxy
Starting to serve on 127.0.0.1:8001

Keep the command above running and start a new terminal session.

Run the following API call from the new terminal window:

$ curl -k -H "Content-Type: application/json" \
          -X PUT \
          --data-binary @tmp.json \
          http://127.0.0.1:8001/api/v1/namespaces/<namespaceName>/finalize

Verify that the terminating Namespace is removed:

$ kubectl get ns <namespaceName>
Error from server (NotFound): namespaces "<namespaceName>" not found

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK