k8s 命名空间问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
douz
V2EX    Kubernetes

k8s 命名空间问题

  •  
  •   douz 194 天前 2640 次点击
    这是一个创建于 194 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    第 1 条附言    194 天前
    排查到新的一条错误信息:AdmissionResponse: UID=c6e3f436-6b2b-4f9b-a394-feac8c88e0eb Code=500 Message=failed to get namespace info from cache: test" allowed=false user="system:serviceaccount:kube-system:replicaset-controller
    第 2 条附言    194 天前
    破案了,集群设置了命名空间的命名规范,必须使用固定的字符串后缀
    14 条回复    2025-03-31 17:36:22 +08:00
    endoffight
        1
    endoffight  
       194 天前   1
    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
        2
    mengyigewen1128  
       194 天前   1
    我帮你百度了下
    在使用 Kubernetes 时,遇到“admission webhook 'node-affinity.k8s.io' denied the request”的错误通常意味着你在创建或更新 Pod 时违反了某些准入控制( admission control )规则。node-affinity.k8s.io 是一个准入控制 webhook ,它负责检查 Pod 调度到节点时的亲和性( affinity )和反亲和性( anti-affinity )规则
    lrh3321
        3
    lrh3321  
       194 天前   1
    kubectl describe validatingwebhookconfigurations node-affinity.k8s.io

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

    https://gist.github.com/ydgo/564200ffe05f641ba6d89d8263e60190
    douz
        5
    douz  
    OP
       194 天前
    @lrh3321 应该是,刚刚又排查到新的一个错误信息
    endoffight
        6
    endoffight  
       194 天前
    https://127.0.0.1:20499/mutating-pods 这个配置有问题,理论上不应该转发到本机,而是集群里的某个 svc
    endoffight
        7
    endoffight  
       194 天前
    不过有可能这只是一个代理,你得找一下具体谁处理的请求
    douz
        8
    douz  
    OP
       194 天前
    @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
        9
    stormtrooperx5  
       194 天前   1
    创一个 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
        10
    endoffight  
       194 天前   1
    试着重启处理这个请求的 pod
    或者找写代码的人

    只能帮你到这儿了
    douz
        11
    douz  
    OP
       194 天前
    @endoffight #10 找了相关负责人,已经破案了
    defunct9
        12
    defunct9  
       194 天前
    那最终是什么问题呢?
    douz
        13
    douz  
    OP
       193 天前
    @defunct9 集群设置了命名空间的命名规范,namespace 必须使用固定的字符串后缀
    defunct9
        14
    defunct9  
       193 天前
    真神经病,难不成所有 pod 都集中在一个 ns 里。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5536 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 09:01 PVG 17:01 LAX 02:01 JFK 05:01
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86