我想通过在 helm 命令行中设置变量来从 values.yaml 中选择配置部分。
values.yaml 的示例部分:
aaa:
x1: "az1"
x2: "az2"
bbb:
x1: "bz1"
x2: "bz2"
configmap.yaml 的示例部分
data:
{{ .Values.outsideVal.x1 }}
预期的结果应该是这样的
data:
az1
测试 helm 输出
helm template --set outsideVal=aaa mychart
得到了这个错误
Error: render error in "./templates/configmap.yaml": template: ./templates/configmap.yaml:21:12: executing "./templates/configmap.yaml" at <.Values.outsideVal.x...>: can't evaluate field x1 in type interface {}
那么问题是如何得到预期的结果?
最佳答案
我怀疑您正在寻找 text/template index
函数,可以通过变量key在map中查找值。
{{ (index .Values .Values.outsideVal).x1 }}
关于kubernetes - 变量值作为 helm 图表中的 yaml 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52407940/