我有一个 HELM 图表,有一些要求(即子图表)。
部署该图表时,我使用 values.yaml
包含主图表和子图表的所有值:
globalFoo: "bar"
subchart1:
foo: subchart1-{{ globalFoo }}
subchart2:
localFoo: "bar2"
foo: subchart2-{{ subchart2.localFoo }}
我想实现两件事:
上面的例子不起作用。我尝试了几种语法,但都没有奏效。我在 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/