gpt4 book ai didi

kubernetes-helm - 引用先前在 HELM values.yaml 中声明的值

转载 作者:行者123 更新时间:2023-12-04 12:17:05 24 4
gpt4 key购买 nike

我有一个 HELM 图表,有一些要求(即子图表)。

部署该图表时,我使用 values.yaml包含主图表和子图表的所有值:

globalFoo: "bar"

subchart1:
foo: subchart1-{{ globalFoo }}

subchart2:
localFoo: "bar2"
foo: subchart2-{{ subchart2.localFoo }}

我想实现两件事:
  • 在子图表值(在我的示例中为 subchart1.foo)中引用先前声明的全局变量(即在全局图表范围内)
  • 在相同的子图表范围内引用先前声明的局部变量(在我的示例中为 subchart2.foo)

  • 上面的例子不起作用。我尝试了几种语法,但都没有奏效。我在 HELM 文档中没有找到类似的内容。

    可行吗?

    最佳答案

    Reference a previously declared global variable in a subchart value, Reference a previously declared local variable in the same subchart scope


    这可以在某种程度上使用 anchors and aliases 来实现。 .
    global: 
    foo: &global-foo bar

    subchart1:
    # this verbatim copies the content of the anchor
    foo: *global-foo
    local: &subchart1-local bar

    subchart2:
    foo: *subchart1-local
    值可以自然地组合在 helm 模板中:
    kind: ConfigMap
    ...
    data:
    FOO: "subchart2-{{ .Values.subchart2.foo }}"
    如果发现自己需要“模板化值” tpl function可能有帮助:
    # values 
    global:
    user: foo
    pass: bar
    dbhost: dbserver.com

    mychart:
    connection: "db://{{.d.user}}:{{d.pass}}/{{d.dbhost}}"

    # template
    kind: ConfigMap
    ...
    data:
    DBURL: "{{ tpl .Values.mychart.connection (dict "d" .Values.global "Template" $.Template }}"
    请注意 (dict ...)语法源自 hint in this helm github comment .这有助于通过提供“.d”上下文而不是“.Values”来缩短模板字符串,即 .d.user .Values.global.user的缩写

    关于kubernetes-helm - 引用先前在 HELM values.yaml 中声明的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58731019/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com