How to force delete a Kubernetes Namespace?

前端 未结 2 563
难免孤独
难免孤独 2021-02-01 19:03

How do I force delete Namespaces stuck in Terminating?

Steps to recreate:

  1. Apply this YAML
apiVersion: v1
kind: Namespace
metadata:         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 19:56

    The kubectl proxy try is almost correct, but not quite. It's possible using JSON instead of YAML does the trick, but I'm not certain.

    The JSON with an empty finalizers list:

    ~$ cat ns.json
    
    {
      "kind": "Namespace",
      "apiVersion": "v1",
      "metadata": {
        "name": "delete-me"
      },
      "spec": {
        "finalizers": []
      }
    }
    

    Use curl to PUT the object without the problematic finalizer.

    ~$ curl -k -H "Content-Type: application/json" -X PUT --data-binary @ns.json http://127.0.0.1:8007/api/v1/namespaces/delete-me/finalize
    
    {
      "kind": "Namespace",
      "apiVersion": "v1",
      "metadata": {
        "name": "delete-me",
        "selfLink": "/api/v1/namespaces/delete-me/finalize",
        "uid": "0df02f91-6782-11e9-8beb-42010a800137",
        "resourceVersion": "39047",
        "creationTimestamp": "2019-04-25T17:46:28Z",
        "deletionTimestamp": "2019-04-25T17:46:31Z",
        "annotations": {
          "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"name\":\"delete-me\"},\"spec\":{\"finalizers\":[\"foregroundDeletion\"]}}\n"
        }
      },
      "spec": {
    
      },
      "status": {
        "phase": "Terminating"
      }
    }
    

    The Namespace is deleted!

    ~$ kubectl get ns delete-me
    
    Error from server (NotFound): namespaces "delete-me" not found
    

提交回复
热议问题