1.强制删除namespace
在尝试以下命令强制删除也不好使:
$ kubectl delete ns —force —grace-period=0
解决方法:
1)运行以下命令以查看处于“Terminating”状态的namespace:
$ kubectl get namespaces
2)选择一个Terminating namespace,并查看namespace 中的finalizer。运行以下命令:
$ kubectl get namespace -o yaml
输出信息如下:
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: “2019-11-20T15:18:06Z”
deletionTimestamp: “2020-01-16T02:50:02Z”
name:
resourceVersion: “3249493”
selfLink: /api/v1/namespaces/knative-eventing
uid: f300ea38-c8c2-4653-b432-b66103e412db
spec:
finalizers:
- kubernetes
status:
3)导出json格式到文件
$ kubectl get namespace -o json >tmp.json
namespace替换成自己的namespace
4)编辑tmp.josn,删除finalizers 字段的值
{
“apiVersion”: “v1”,
“kind”: “Namespace”,
“metadata”: {
“creationTimestamp”: “2019-11-20T15:18:06Z”,
“deletionTimestamp”: “2020-01-16T02:50:02Z”,
“name”: “”,
“resourceVersion”: “3249493”,
“selfLink”: “/api/v1/namespaces/knative-eventing”,
“uid”: “f300ea38-c8c2-4653-b432-b66103e412db”
},
“spec”: { #从此行开始删除
“finalizers”: []
}, # 删到此行
“status”: {
“phase”: “Terminating”
}
}
5)开启proxy
$ kubectl proxy
执行该命令后,当前终端会被卡住
6)打开新的一个窗口,执行以下命令
$ curl -k -H “Content-Type: application/json” -X PUT —data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/你的namespace/finalize
输出信息如下:
{
“kind”: “Namespace”,
“apiVersion”: “v1”,
“metadata”: {
“name”: “istio-system”,
“selfLink”: “/api/v1/namespaces/istio-system/finalize”,
“uid”: “2e274537-727f-4a8f-ae8c-397473ed619a”,
“resourceVersion”: “3249492”,
“creationTimestamp”: “2019-11-20T15:18:06Z”,
“deletionTimestamp”: “2020-01-16T02:50:02Z”
},
“spec”: {
},
“status”: {
“phase”: “Terminating”
}
}
7)确认处于Terminating 状态的namespace已经被删除
$ kubectl get namespaces
如果还有处于Terminating 状态的namespace,重复以上操作,删除即可!