创建 deployment 时的报错信息:admission webhook "node-affinity.k8s.io" denied the request: failed to get namespace info from cache: test
目前只能用一个指定的命名空间(比如 first )创建 deployment 时不会报错,这个 first 命名空间也是一开始创建 deployment 使用的一个,后面换其他的命名空间都会报上面这个错误。大佬们知道如何排查解决么?
![]() | 1 endoffight 194 天前 ![]() kubectl get ns 先看看你是使用的命名空间是否存在 如果存在,说明你的 webhook 有问题 kubectl get validatingwebhookconfiguration -o yaml | grep "node-affinity.k8s.io" kubectl get mutatingwebhookconfiguration -o yaml | grep "node-affinity.k8s.io" 找到你的 webhook ,然后看是不是有 bug |
![]() | 2 mengyigewen1128 194 天前 ![]() 我帮你百度了下 在使用 Kubernetes 时,遇到“admission webhook 'node-affinity.k8s.io' denied the request”的错误通常意味着你在创建或更新 Pod 时违反了某些准入控制( admission control )规则。node-affinity.k8s.io 是一个准入控制 webhook ,它负责检查 Pod 调度到节点时的亲和性( affinity )和反亲和性( anti-affinity )规则 |
![]() | 3 lrh3321 194 天前 ![]() kubectl describe validatingwebhookconfigurations node-affinity.k8s.io 感觉可能是 node-affinity.k8s.io 这个 WebHook 权限配错了,读取不了其他命名空间的信息 |
![]() | 4 douz OP @endoffight 命名空间是存在的,我看了具体的 webhook 是这样的,是否可以看出来哪里有问题呢? https://gist.github.com/ydgo/564200ffe05f641ba6d89d8263e60190 |
![]() | 6 endoffight 194 天前 https://127.0.0.1:20499/mutating-pods 这个配置有问题,理论上不应该转发到本机,而是集群里的某个 svc |
![]() | 7 endoffight 194 天前 不过有可能这只是一个代理,你得找一下具体谁处理的请求 |
![]() | 8 douz OP @endoffight #7 确实有一个代理 pod 在处理这个请求,看了下这个 pod 的日志也对得上 time="2025-03-31T02:36:49Z" level=error msg="failed to get namespace info from cache: test" time="2025-03-31T02:36:49Z" level=warning msg="AdmissionResponse: UID=fe54e21b-08c4-48d6-a6cd-52539e4ccbf0 Code=500 Message=failed to get namespace info from cache: test" allowed=false user="system:serviceaccount:kube-system:replicaset-controller" |
![]() | 9 stormtrooperx5 194 天前 ![]() 创一个 clusterrole ,叫 xxx ,创一个 service account 叫 yyy ,用 clusterrolebinding 把这个 sa 和 clusterrole 绑定起来,赋予* namespace 下的 get 、list 、watch 等权限。然后 kubectl get sa yyy -n [NAMESPACE] -o yaml ,拿到 token ,加到你的 wehbook 的 req header 里面 |
![]() | 10 endoffight 194 天前 ![]() 试着重启处理这个请求的 pod 或者找写代码的人 只能帮你到这儿了 |
![]() | 11 douz OP @endoffight #10 找了相关负责人,已经破案了 |
![]() | 12 defunct9 194 天前 那最终是什么问题呢? |
![]() | 14 defunct9 193 天前 真神经病,难不成所有 pod 都集中在一个 ns 里。 |