1.导出namespace信息
导出json格式的namespace信息,拿到此namespace的描述信息(这里以名称空间cloudwatch为例)
~]# kubectl get ns cloudwatch -o json > cloudwatch.json
2.编辑导出的json文件,删除spec中的内容
删除后参考如下:
~]# more cloudwatch.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"labels\":{\"name\":\"cloudwatch\"},\"name\":\"cloudwatch\"}}\n"
},
"creationTimestamp": "2020-12-01T08:41:41Z",
"deletionTimestamp": "2020-12-01T09:03:38Z",
"labels": {
"name": "cloudwatch"
},
"name": "cloudwatch",
"resourceVersion": "52355755",
"selfLink": "/api/v1/namespaces/cloudwatch",
"uid": "43a1e77c-5788-4242-b445-adec523aaa6f"
},
"spec": {
},
"status": {
"phase": "Terminating"
}
}
3.kubectl开启一个本地代理
默认端口为8001,也可以通过参数–port=8081指定自定义端口
~]# kubectl proxy
Starting to serve on 127.0.0.1:8001
4.通过API接口运行如下命令进行删除
curl -k -H "Content-Type: application/json" -X PUT --data-binary @cloudwatch.json http://127.0.0.1:8001/api/v1/namespaces/cloudwatch/finalize
提示:如上命令相关参数需要根据实际情况进行修改。
评论前必须登录!
注册