V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
foMM

k8s patch deployment 的 image 和 imagePullSecrets 的方法

  •  
  •   foMM · Oct 22, 2020 · 3981 views
    This topic created in 2019 days ago, the information mentioned may be changed or developed.

    尝试过可以用kubectl edit deployment xxx 可以成功

    但是用

    kubectl patch deployment xxx -n xxx -p \
      '{"spec":{"template":{"spec":{"containers":[{"image":"new_image"}],"imagePullSecrets":[{"name":"new-secret"}]}}}}'
    

    报错

    Error from server: map: map[image:new_image] does not contain declared merge key: name
    

    请教一下如何可以不使用 kubectl edit 的方式来更新 deployment 的imageimagePullSecrets

    感谢

    6 replies    2020-10-22 10:23:48 +08:00
    wd
        1
    wd  
       Oct 22, 2020 via iPhone
    错误不是说的很明白了么 你需要给 name 它才知道你是 patch 旧的 还是加新的 container 啊
    binux
        2
    binux  
       Oct 22, 2020 via Android
    用 JSON op 方式修改
    foMM
        3
    foMM  
    OP
       Oct 22, 2020
    @wd #1 不好意思,请问需要给一个什么样的 name 才能 override 之前的值呢?

    @binux #2 感谢。我尝试了一下

    kubectl patch deployment xxx -n xxx --type json -p '[{"op":"replace","path":"spec/template/spec/containers/image","value":"new_image"},{"op":"replace","path":"spec/template/spec/imagePullSecrets/name","value":"new_secrete"}]'

    Response 是:The request is invalid
    binux
        4
    binux  
       Oct 22, 2020   ❤️ 1
    /spec/template/spec/containers/0/image
    0bit
        5
    0bit  
       Oct 22, 2020   ❤️ 1
    没直接用过 patch 修改,瞎猜的:
    containers 里是一个数组[ ],可能是需要指定 name 来说明你要修改的是哪一个 container ?毕竟还有可能有 sidecar 之类的配置。

    另外,感觉还是直接维护 Helm Chart 更好, 之后只要改 values.yaml,然后 helm upgrade 就行了。
    foMM
        6
    foMM  
    OP
       Oct 22, 2020
    @binux #4
    @0bit #5

    感谢,确实是数组的原因。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2683 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:19 · PVG 22:19 · LAX 07:19 · JFK 10:19
    ♥ Do have faith in what you're doing.