删除 NameSpace 时长时间无法删除
删除 NameSpace 时长时间无法删除
最主要的原因是 finalizers
列表中还有资源未被删除
apiVersion: v1
kind: Namespace
metadata:
annotations:
cattle.io/status: '{"Conditions":[{"Type":"InitialRolesPopulated","Status":"True","Message":"","LastUpdateTime":"2022-02-25T03:01:32Z"},{"Type":"ResourceQuotaValidated","Status":"Unknown","Message":"Validating
resource quota","LastUpdateTime":""},{"Type":"ResourceQuotaInit","Status":"True","Message":"","LastUpdateTime":"2022-02-25T03:01:27Z"}]}'
field.cattle.io/creatorId: user-vwgkp
field.cattle.io/projectId: c-z5hbl:p-n5clr
lifecycle.cattle.io/create.namespace-auth: "true"
creationTimestamp: "2022-02-25T10:57:38Z"
deletionTimestamp: "2022-02-25T11:18:40Z"
labels:
cattle.io/creator: norman
field.cattle.io/projectId: p-n5clr
managedFields:
manager: kube-controller-manager
operation: Update
time: "2022-03-14T10:46:37Z"
name: my-test
resourceVersion: "188871796"
selfLink: /api/v1/namespaces/mss-test
uid: e3df5ad1-f4b0-435b-98fb-108d45e6b783
spec:
finalizers: # 这里的值必须为空才可以删除
- kubernetes
status:
conditions:
- lastTransitionTime: "2022-02-25T03:23:02Z"
message: 'Discovery failed for some groups, 1 failing: unable to retrieve the
complete list of server APIs: subresources.kubevirt.io/v1alpha3: the server
is currently unable to handle the request'
reason: DiscoveryFailed
status: "True"
type: NamespaceDeletionDiscoveryFailure
解决办法
#!/bin/bash
# auther: sober
echo "start a kube proxy port 8001"
kubectl proxy --port=8001 &
jobs
sleep 10
NAME_SPACES="$1"
echo "You will delete k8s namespaces $NAME_SPACES"
cat <<EOF | curl -X PUT \
127.0.0.1:8001/api/v1/namespaces/$NAME_SPACES/finalize \
-H "Content-Type: application/json" \
--data-binary @-
{
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "$NAME_SPACES"
},
"spec": {
"finalizers": null
}
}
EOF
for i in {1..5}
do
echo ""
done
echo "show the kubectl cluster namespaces ,now!"
kubectl get ns