The little apprentice

Curiosities over computing

Home Blog Wordpress About me

Delete namespaces in state terminating permanent in Kubernetes

Sometimes when we go to delete a namespace and this namespace is in state terminating permanently, we have that to do the next steps for delete definitly of our cluster of Kubernetes.

kubectl get namespaces

NAME             STATUS        AGE
cert-manager     Terminating   47m
default          Active        1y
kube-public      Active        1y
kube-system      Active        1y
kubectl delete all -n <terminating-namespace> --all --force --grace-period=0
kubectl delete ns <terminating-namespace> --force --grace-period=0
kubectl get namespace <terminating-namespace> -o yaml

{
  "kind": "Namespace",
  "apiVersion": "v1",
  "metadata": {
    "name": "cert-manager",
    "selfLink": "/api/v1/namespaces/cert-manager/finalize",
    "uid": "da5f8b60-f56f-11e9-aa9f-42010a840091",
    "resourceVersion": "143886220",
    "creationTimestamp": "2019-10-23T08:33:56Z",
    "deletionTimestamp": "2019-10-23T09:05:06Z"
  },
  "spec": {
    "finalizers": [
      "kubernetes"
    ]
  },
  "status": {
    "phase": "Terminating"
  }
}
 kubectl get namespace <terminating-namespace> -o json >tmp.json
nano tmp.json


{
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
        "creationTimestamp": "2019-10-23T08:33:56Z",
        "deletionTimestamp": "2019-10-23T09:05:06Z",
        "name": "cert-manager",
        "resourceVersion": "143886220",
        "selfLink": "/api/v1/namespaces/cert-manager",
        "uid": "da5f8b60-f56f-11e9-aa9f-42010a840091"
    },
    "spec": {
        "finalizers":[]
    },
    "status": {
        "phase": "Terminating"
    }
}
kubectl proxy

This command executed must show the following information:

Starting to serve on 127.0.0.1:8001
curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/<terminating-namespace>/finalize

This command executed must show the following information:

{
  "kind": "Namespace",
  "apiVersion": "v1",
  "metadata": {
    "name": "cert-manager",
    "selfLink": "/api/v1/namespaces/cert-manager/finalize",
    "uid": "da5f8b60-f56f-11e9-aa9f-42010a840091",
    "resourceVersion": "143898297",
    "creationTimestamp": "2019-10-23T08:33:56Z",
    "deletionTimestamp": "2019-10-23T09:05:06Z"
  },
  "spec": {
    
  },
  "status": {
    "phase": "Terminating"
  }
}
kubectl get namespaces

NAME             STATUS        AGE
default          Active        1y
kube-public      Active        1y
kube-system      Active        1y