k8s 命名空间问题

67 天前
 douz

创建 deployment 时的报错信息:admission webhook "node-affinity.k8s.io" denied the request: failed to get namespace info from cache: test

目前只能用一个指定的命名空间(比如 first )创建 deployment 时不会报错,这个 first 命名空间也是一开始创建 deployment 使用的一个,后面换其他的命名空间都会报上面这个错误。大佬们知道如何排查解决么?

2213 次点击
所在节点    Kubernetes
14 条回复
endoffight
67 天前
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
mengyigewen1128
67 天前
我帮你百度了下
在使用 Kubernetes 时,遇到“admission webhook 'node-affinity.k8s.io' denied the request”的错误通常意味着你在创建或更新 Pod 时违反了某些准入控制( admission control )规则。node-affinity.k8s.io 是一个准入控制 webhook ,它负责检查 Pod 调度到节点时的亲和性( affinity )和反亲和性( anti-affinity )规则
lrh3321
67 天前
kubectl describe validatingwebhookconfigurations node-affinity.k8s.io

感觉可能是 node-affinity.k8s.io 这个 WebHook 权限配错了,读取不了其他命名空间的信息
douz
67 天前
@endoffight 命名空间是存在的,我看了具体的 webhook 是这样的,是否可以看出来哪里有问题呢?

https://gist.github.com/ydgo/564200ffe05f641ba6d89d8263e60190
douz
67 天前
@lrh3321 应该是,刚刚又排查到新的一个错误信息
endoffight
67 天前
https://127.0.0.1:20499/mutating-pods 这个配置有问题,理论上不应该转发到本机,而是集群里的某个 svc
endoffight
67 天前
不过有可能这只是一个代理,你得找一下具体谁处理的请求
douz
67 天前
@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"
stormtrooperx5
67 天前
创一个 clusterrole ,叫 xxx ,创一个 service account 叫 yyy ,用 clusterrolebinding 把这个 sa 和 clusterrole 绑定起来,赋予* namespace 下的 get 、list 、watch 等权限。然后 kubectl get sa yyy -n [NAMESPACE] -o yaml ,拿到 token ,加到你的 wehbook 的 req header 里面
endoffight
67 天前
试着重启处理这个请求的 pod
或者找写代码的人

只能帮你到这儿了
douz
67 天前
@endoffight #10 找了相关负责人,已经破案了😂
defunct9
67 天前
那最终是什么问题呢?
douz
67 天前
@defunct9 集群设置了命名空间的命名规范,namespace 必须使用固定的字符串后缀
defunct9
67 天前
真神经病,难不成所有 pod 都集中在一个 ns 里。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://yangjunhui.monster/t/1122181

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX