我遇到了 Kubernetes 命名空间陷入“终止”状态的问题。运行kubectl get ns cattle-monitoring-system -o json|jq
会产生与命名空间状态相关的错误消息custom.metrics.k8s.io/v1beta1
,并显示DiscoveryFailed
命名空间状态中的条件:
E1213 08:02:39.979034 953148 memcache.go:287] couldn't get resource list for custom.metrics.k8s.io/v1beta1: the server is currently unable to handle the request
…
{
"apiVersion": "v1",
"kind": "Namespace",
…
"status": {
"conditions": [
{
"lastTransitionTime": "2023-12-12T14:53:40Z",
"message": "Discovery failed for some groups, 1 failing: unable to retrieve the complete list of server APIs: custom.metrics.k8s.io/v1beta1: the server is currently unable to handle the request",
"reason": "DiscoveryFailed",
"status": "True",
"type": "NamespaceDeletionDiscoveryFailure"
},
…
]
}
}
如何解决此问题以成功删除命名空间?
答案1
您遇到的问题与 Kubernetes API 服务器无法发现 custom.metrics.k8s.io/v1beta1 API 有关,这会阻止命名空间终止。以下是排查和解决此问题的步骤:
检查关联的 APIService
调查 custom.metrics.k8s.io/v1beta1 是否有 APIService:
kubectl get apiservices.apiregistration.k8s.io -o json|jq '.items[]|select(.metadata.name=="v1beta1.custom.metrics.k8s.io")'
输出应该是这样的
{
"apiVersion": "apiregistration.k8s.io/v1",
"kind": "APIService",
...
"status": {
"conditions": [
{
"message": "service/example-service in \"example-namespace\" is not present",
"reason": "ServiceNotFound",
"status": "False",
"type": "Available"
}
]
}
}
验证没有与 APIService 相关的活动组件:
发出以下命令。example-service
根据您之前生成的输出进行调整。
for c in configmaps secrets deployments statefulsets pods services; do
echo "Checking for $c related to example-service"
kubectl get $c -A | grep example-service
done
如果没有输出,则确认集群中没有与 APIService 相关的活动组件。
删除API服务
kubectl delete apiservice v1beta1.custom.metrics.k8s.io
删除 APIService 后,命名空间应继续终止。监视集群是否存在任何意外问题。