1. 查看kubectl get ns 查看处于Terminating的ns
[root@m01 ~]# kubectl get ns istio-system
NAME STATUS AGE
istio-system Terminating 41h
2. 将处理 Terminating的ns的描述文件保存下来
[root@m01 ~]# kubectl get ns istio-system -o json > istio-system.json
[root@m01 ~]# cat istio-system.json
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"creationTimestamp": "2021-03-23T09:14:05Z",
"deletionTimestamp": "2021-03-25T02:23:32Z",
"labels": {
"istio-injection": "disabled"
},
"managedFields": [
{
"apiVersion": "v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:labels": {
".": {},
"f:istio-injection": {}
}
},
"f:status": {
"f:phase": {}
}
},
"manager": "istioctl",
"operation": "Update",
"time": "2021-03-23T09:14:05Z"
},
{
"apiVersion": "v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:status": {
"f:conditions": {
".": {},
"k:{\"type\":\"NamespaceContentRemaining\"}": {
".": {},
"f:lastTransitionTime": {},
"f:message": {},
"f:reason": {},
"f:status": {},
"f:type": {}
},
"k:{\"type\":\"NamespaceDeletionContentFailure\"}": {
".": {},
"f:lastTransitionTime": {},
"f:message": {},
"f:reason": {},
"f:status": {},
"f:type": {}
},
"k:{\"type\":\"NamespaceDeletionDiscoveryFailure\"}": {
".": {},
"f:lastTransitionTime": {},
"f:message": {},
"f:reason": {},
"f:status": {},
"f:type": {}
},
"k:{\"type\":\"NamespaceDeletionGroupVersionParsingFailure\"}": {
".": {},
"f:lastTransitionTime": {},
"f:message": {},
"f:reason": {},
"f:status": {},
"f:type": {}
},
"k:{\"type\":\"NamespaceFinalizersRemaining\"}": {
".": {},
"f:lastTransitionTime": {},
"f:message": {},
"f:reason": {},
"f:status": {},
"f:type": {}
}
}
}
},
"manager": "kube-controller-manager",
"operation": "Update",
"time": "2021-03-25T02:23:38Z"
}
],
"name": "istio-system",
"resourceVersion": "2372643",
"selfLink": "/api/v1/namespaces/istio-system",
"uid": "f33afeaf-bf16-4840-a47d-663d7ba7c880"
},
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"conditions": [
{
"lastTransitionTime": "2021-03-25T02:23:37Z",
"message": "Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: the server is currently unable to handle the request",
"reason": "DiscoveryFailed",
"status": "True",
"type": "NamespaceDeletionDiscoveryFailure"
},
{
"lastTransitionTime": "2021-03-25T02:23:38Z",
"message": "All legacy kube types successfully parsed",
"reason": "ParsedGroupVersions",
"status": "False",
"type": "NamespaceDeletionGroupVersionParsingFailure"
},
{
"lastTransitionTime": "2021-03-25T02:23:38Z",
"message": "All content successfully deleted, may be waiting on finalization",
"reason": "ContentDeleted",
"status": "False",
"type": "NamespaceDeletionContentFailure"
},
{
"lastTransitionTime": "2021-03-25T02:24:15Z",
"message": "All content successfully removed",
"reason": "ContentRemoved",
"status": "False",
"type": "NamespaceContentRemaining"
},
{
"lastTransitionTime": "2021-03-25T02:23:38Z",
"message": "All content-preserving finalizers finished",
"reason": "ContentHasNoFinalizers",
"status": "False",
"type": "NamespaceFinalizersRemaining"
}
],
"phase": "Terminating"
}
}
删除此部份
,
"spec": {
"finalizers": [
"kubernetes"
]
},
"status": {
"conditions": [
{
"lastTransitionTime": "2021-03-25T02:23:37Z",
"message": "Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: metrics.k8s.io/v1beta1: the server is currently unable to handle the request",
"reason": "DiscoveryFailed",
"status": "True",
"type": "NamespaceDeletionDiscoveryFailure"
},
{
"lastTransitionTime": "2021-03-25T02:23:38Z",
"message": "All legacy kube types successfully parsed",
"reason": "ParsedGroupVersions",
"status": "False",
"type": "NamespaceDeletionGroupVersionParsingFailure"
},
{
"lastTransitionTime": "2021-03-25T02:23:38Z",
"message": "All content successfully deleted, may be waiting on finalization",
"reason": "ContentDeleted",
"status": "False",
"type": "NamespaceDeletionContentFailure"
},
{
"lastTransitionTime": "2021-03-25T02:24:15Z",
"message": "All content successfully removed",
"reason": "ContentRemoved",
"status": "False",
"type": "NamespaceContentRemaining"
},
{
"lastTransitionTime": "2021-03-25T02:23:38Z",
"message": "All content-preserving finalizers finished",
"reason": "ContentHasNoFinalizers",
"status": "False",
"type": "NamespaceFinalizersRemaining"
}
],
"phase": "Terminating"
}
3.本地启动kube-proxy
kubectl proxy
kubectl proxy --port=8001
4.新开窗口执行删除操作
curl -k -H "Content-Type: application/json" -X PUT --data-binary @istio-system.json http://127.0.0.1:8001/api/v1/namespaces/istio-system/finalize
5.删除namespace
# 正常删除
kubectl delete namespace istio-system
# 强制删除
kubectl delete namespace istio-system --force --grace-period=0
rancher删除Terminaling的命名空间
首先要安装jq:
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum install jq
设置要删除命名空间的名称:
NAMESPACE=test
接着执行如下操作:
# 获取RANCHER_SERVER_URL地址
RANCHER_SERVER_URL=$( kubectl config view -o json|jq -r .clusters[0].cluster.server )
# 获取config中的token
CLUSTER_TOKEN=$( kubectl config view -o json|jq -r .users[0].user.token )
# kubectl get ns ${NAMESPACE} -ojson| \
jq 'del(.spec.finalizers[])'| \
jq 'del(.metadata.finalizers)' > ${NAMESPACE}.json
curl -k -H "Content-Type: application/json" \
-H "Authorization: Bearer ${CLUSTER_TOKEN}" \
-X PUT --data-binary @${NAMESPACE}.json \
${RANCHER_SERVER_URL}/api/v1/namespaces/${NAMESPACE}/finalize