1. Run the following command to view the namespaces that are stuck in the Terminating state:
kubectl get namespaces
2. Select a terminating namespace and view the contents of the namespace to find out the finalizer
. Run the following command:
kubectl get namespace <terminating-namespace> -o yaml
Your YAML contents might resemble the following output:
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: 2018-11-19T18:48:30Z
deletionTimestamp: 2018-11-19T18:59:36Z
name: <terminating-namespace>
resourceVersion: "1385077"
selfLink: /api/v1/namespaces/<terminating-namespace>
uid: b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5
spec:
finalizers:
- kubernetes
status:
phase: Terminating
3. Select cluster Id from Rancher URL:
https://<rancher_host>/c/c-hh7dl/projects-namespaces
4. Set a temporary proxy IP and port, run the following command. Be sure to keep your terminal window open until you delete the stuck namespace:
kubectl proxy
5.From a new terminal window, make an API call with your temporary proxy IP and port:
( NAMESPACE=<terminating-namespace>; CLUSTER=<namespace>;kubectl get namespace $NAMESPACE -o json |jq ‘.spec = {“finalizers”:[]}’ >temp.json; curl -k -H “Content-Type: application/json” -X PUT — data-binary @temp.json 127.0.0.1:8001/k8s/clusters/$CLUSTER/api/v1/namespaces/$NAMESPACE/finalize; )
Your output might resemble the following content:
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "test123123",
"selfLink": "/api/v1/namespaces/test123123/finalize",
"uid": "06a9f9ff-9b5f-4036-bc6d-956e12010487",
"resourceVersion": "10867032",
"creationTimestamp": "2019-11-28T07:41:41Z",
"deletionTimestamp": "2019-11-28T07:41:46Z",
"labels": {
"cattle.io/creator": "norman",
"field.cattle.io/projectId": "p-4dbdx"
},
"annotations": {
"cattle.io/status": "{\"Conditions\":[{\"Type\":\"InitialRolesPopulated\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2019-11-28T07:43:23Z\"},{\"Type\":\"ResourceQuotaValidated\",\"Status\":\"Unknown\",\"Message\":\"Validating resource quota\",\"LastUpdateTime\":\"\"},{\"Type\":\"ResourceQuotaInit\",\"Status\":\"True\",\"Message\":\"\",\"LastUpdateTime\":\"2019-11-28T07:43:22Z\"}]}",
"field.cattle.io/creatorId": "user-zzxjh",
"field.cattle.io/projectId": "c-hh7dl:p-4dbdx",
"lifecycle.cattle.io/create.namespace-auth": "true"
}
},
"spec": {
},
"status": {
"phase": "Terminating"
}