Skip to content

Instantly share code, notes, and snippets.

@harivemula
Last active September 3, 2021 05:51
Show Gist options
  • Save harivemula/e97020acc8821f57f19e34046d590c16 to your computer and use it in GitHub Desktop.
Save harivemula/e97020acc8821f57f19e34046d590c16 to your computer and use it in GitHub Desktop.
Deleting the namespace stuck in 'terminating' state.

Deleting the Kubernetes Namespace if it is stuck with finalizers

kubectl get ns <your-name-space> | kubectl neat > temp-ns.json

Note: The kubectl neat is optional.

Output of the above might looks like below content, remove the "kubernetes" under finalizers array and save the file.

{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {"name":"test"},
    "spec": {
        "finalizers": [
            "kubernetes"
        ]
    }
}

Run `kubectl proxy' in another terminal then

curl -X PUT http://localhost:8001/api/v1/namespaces/<your-namespace>/finalize -H "Content-Type: application/json" --data @temp-ns.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment