公司的DEV kubernetes环境需要重新搭建,在搭建的过程中,发现了一个有趣的现象,在尝试kubectl delete ns XX
的时候, namespace一直卡在了Terminating
的状态上.
在尝试了诸多方式后,只有直接调用ApiService的API才可行,具体方法:
kubectl get secrets
kubectl describe secrets xxx (anyone is good enough)
export TOKEN=(you get from above)
curl https://your-cluster-ip:6443/api/v1/namespaces --header "Authorization: Bearer $TOKEN" --insecure
curl -X PUT --data-binary @tmp.json https://your-cluster-ip:6443/api/v1/namespaces/the-namespace-you-wanto-delete/finalize -H "Content-Type: application/json" --header "Authorization: Bearer $TOKEN" --insecure
在取token的时候,任何一个secret都可以,只要可以访问apiservice即可.
附上references:
https://success.docker.com/article/kubernetes-namespace-stuck-in-terminating
https://github.com/kubernetes/kubernetes/issues/60807
https://github.com/kubernetes/kubectl/issues/151
https://medium.com/@newtondev/how-to-fix-kubernetes-namespace-deleting-stuck-in-terminating-state-5ed75792647e