kubernetes: Kubernetes namespaces stuck in terminating state
I tried to delete some namespaces from my kubernetes cluster, but they’ve been stuck in Terminating state for over a month.
kubectl get ns
NAME LABELS STATUS AGE
myproject <none> Active 12d
default <none> Active 40d
anotherproject <none> Terminating 40d
openshift <none> Terminating 40d
openshift-infra <none> Terminating 40d
The openshift namespaces were made as part of the example in this repo for running Openshift under Kube.
There’s nothing in any of these namespaces (I used get on every resource type and they’re all empty).
So what’s holding up the terminate?
The kube cluster is healthy:
NAME STATUS MESSAGE ERROR
etcd-1 Healthy {"health": "true"}
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {"health": "true"}
The versions are:
Client Version: version.Info{Major:"1", Minor:"2+", GitVersion:"v1.2.0-alpha.4.208+c39262c9915b0b", GitCommit:"c39262c9915b0b1c493de66f37c49f3ef587cd97", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"2+", GitVersion:"v1.2.0-alpha.4.166+d9ab692edc08a2", GitCommit:"d9ab692edc08a279396b29efb4d7b1e6248dfb60", GitTreeState:"clean"}
The server version corresponds to this commit: https://github.com/paralin/kubernetes/commit/d9ab692edc08a279396b29efb4d7b1e6248dfb60
Compiled from source. Cluster was built using kube-up to GCE with the following env:
export KUBERNETES_PROVIDER=gce
export KUBE_GCE_ZONE=us-central1-b
export MASTER_SIZE=n1-standard-1
export MINION_SIZE=n1-standard-2
export NUM_MINIONS=3
export KUBE_ENABLE_NODE_AUTOSCALER=true
export KUBE_AUTOSCALER_MIN_NODES=3
export KUBE_AUTOSCALER_MAX_NODES=3
export KUBE_ENABLE_DAEMONSETS=true
export KUBE_ENABLE_DEPLOYMENTS=true
export KUBE_ENABLE_INSECURE_REGISTRY=true
Any ideas?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 16
- Comments: 66 (17 by maintainers)
@paralin - there is no code issue, but maybe I can look to improve in the openshift example clean-up scripts or document the steps. When you created a project in openshift, it created a namespace for that project, and annotated the namespace with a
finalizer
token that said before a namespace is deleted, an external agent needs to remove its lock on the object that says it was done clean-up. Since you are no longer running openshift, its agent did not remove the lock and take part in the termination flow.A quick fix:
That will remove the lock that blocks the namespace from being completely terminated, and you should quickly see that the namespace is removed from your system.
Closing the issue, but feel free to comment if you continue to have problems or hit me up on slack.
have you tried to delete it using the following script ?
I have already the same problem. I restarted the virtual machine, and also run “kubectl delete ns ***** --force --grace-period=0”. The namespace concerned is still stucking in Terminating.
@attila123 I was having the same issue. In the case of rook it creates a finalizer which was causing it to get stuck.
Directly from the cleanup docs:
The operator is responsible for removing the finalizer after the mounts have been cleaned up. If for some reason the operator is not able to remove the finalizer (ie. the operator is not running anymore), you can delete the finalizer manually.
Look for the finalizers element and delete the following line:
Now save the changes and exit the editor. Within a few seconds you should see that the cluster CRD has been deleted and will no longer block other cleanup such as deleting the rook namespace.
Resolved using the script from this comment.
Getting this issue in
1.14.3
.I deleted a namespace, and it shows as permanently “Terminating”. Removing the finalizer made no difference, and there are no pods running in the ns.
Hi, I got the same problem with Kubernetes 1.9.0 running by Minikube v0.24.1. I started too many pods my laptop kept swapping and not responding. So I powered that off. Upon restart lots of pods stucked, but I could delete them with
kubectl -n some_namespace delete pod --all --grace-period=0 --force
(first I deleted all the deployments, services, etc.) I also installed rook (0.7.0) and its namespace get stuck, even after minikube restart (stop + start).I needed to move on with my work, so I stopped minikube, stopped the host VM, created a full clone of it in Virtualbox, so if there is anything I can check, any log, etc., I can provide it. Then I
minikube delete
-ed my cluster. If I remember correctly, no resource was present in the rook namespace.I’m facing the same issue
I have deleted the project named “gitlab” via Openshift Origin web console. But it is not removed.
As said by @derekwaynecarr I did the following
and
but it is removed.
kubectl get namespace annoying-namespace-to-delete -o json > tmp.json then edit tmp.json and remove"kubernetes"
curl -k -H “Content-Type: application/json” -X PUT --data-binary @tmp.json https://kubernetes-cluster-ip/api/v1/namespaces/annoying-namespace-to-delete/finalize
and it should delete your namespace,
Hi, I got this:
curl -H “Content-Type: application/json” -X PUT --data-binary @temp.json http://127.0.0.1:8001/api/v1/namespaces/cattle-system/finalize/ { “kind”: “Status”, “apiVersion”: “v1”, “metadata”: {
}, “status”: “Failure”, “message”: “Operation cannot be fulfilled on namespaces "cattle-system": the object has been modified; please apply your changes to the latest version and try again”, “reason”: “Conflict”, “details”: { “name”: “cattle-system”, “kind”: “namespaces” }, “code”: 409
UPDATE: for those who got it, remove in json all line:
“resourceVersion”: “somenumber”,
And rerun curl
in my case, it was cert-managaer ns, which stuck in termination state. It could not be delete because of CRDs which was created before but was not seen by cmd
kubectl get all
but link to the script which has been provided by @difabion do the job. thx @difabionI have not, no. Incredible that such an issue has been unfixed for over three years.
Also worked for me in EKS. Just needed to use proxy
k proxy
and thencurl
localhostRemoving finalizer worked for me. I PUT empty spec property and removed status property completely. Used kubectl proxy and
http://localhost:8001/api/v1/namespaces/{namespace_name}/finalizer
as the endpointI came across this issue when cleaning up our staging cluster, which our developers use a lot. We use a cluster with nodes provisioned through rancher at Digitalocean. For the other people ending here after googling this issue and looking for an easy way to remove these namespaces, i will leave the shell script I’ve written for these cases here, please use it with care:
The (old but effective) comment from @derekwaynecarr did the trick for me
https://github.com/kubernetes/kubernetes/issues/19317#issuecomment-180003984
the only missing step for me was
kubectl proxy
and changing the port number accordingly (8001 instead of 8080)I’m hitting this issue on v1.6.10-gke.1 – ns stuck in ‘terminating’ after 1d. Looks like a regression. Manually deleting the finalizer fixed the problem. Here’s a dump of my NS data;
I use
kubectl edit namespace ****
and remove the finalizer part, and save.https://github.com/rancher/rancher/issues/14715#issuecomment-407900343
got the issue on EKS (Kubernetes version: 1.15) kubectl version:
The kill-kube-ns script works for me. Thank you.
None of these suggestions worked and after realising I could be looking at wasting hours trying to fix it, I came to the conclusion that if many equally capable devs had tried before me then I would be wasting my time for something so insignificant. Just deleting the kubernetes data and settings (through the Docker Desktop client) worked fine. You should have scripts for setting up your clusters and stuff anyway so no harm there if you’re in a dev environment.
Can we reopen this issue?
following @derekwaynecarr workaround - which helped me allot - wrote this script which will delete all terminating projects. sort of cleanup script. please someone tell me, i am one RedHat Openshift Enterprise! 3.7 and facing this issue. its so stupid that even i will just create an project and immediatley will delete it i will stumble on this issue. isnt this crazy?!?!!? the enterprise version cost fortune. please just tell me i am not crazy.
this is the script; (uses jq, tested with redhat openshift ocp 3.7)
kubectl proxy & serverPID=$! for row in $(oc get ns -o json | jq -r ‘.items[] | select(.status.phase==“Terminating”) | .metadata.name’); do echo “force deleting name space ${row}” oc project $row oc delete --all all,secret,pvc > /dev/null oc get ns $row -o json > tempns sed -i ‘’ ‘/“kubernetes”/d’ ./tempns curl --silent --output /dev/null -H “Content-Type: application/json” -X PUT --data-binary @tempns http://127.0.0.1:8001/api/v1/namespaces/$row/finalize done kill -9 $serverPID
we are hitting this issue atm on 1.5.2
https://github.com/kubernetes/kubernetes/issues/37554 https://github.com/kubernetes/kubernetes/issues/37278
we are hitting this issue atm on 1.4.6; edit: actually our issue is https://github.com/kubernetes/kubernetes/issues/37278
In my case, ThirdPartyResource had been kept on Etcd. Stucked namespaces was removed after deleting it like this.