Kubernetes 在 values.yaml 中使用 {{ include xx }}
Kubernetes use {{ include xx }} inside values.yaml
我正在重构一个 helm chart,我想输入一些从 deployment.yaml
到 values.yaml
的值,这个值是
hosts:
- {{ include "myApp.externalHostName" . | quote }}
但它给了我错误
[ERROR] values.yaml: unable to parse YAML: error converting YAML to
JSON: yaml: invalid map key: map[interface {}]interface {}{"toJson
include \"myApp.externalHostName\" . | quote":interface {}(nil)}
[ERROR] templates/: cannot load values.yaml: error converting YAML to
JSON: yaml: invalid map key: map[interface {}]interface {}{"toJson
include \"myApp.externalHostName\" . | quote":interface {}(nil)}
如果我只使用它就可以了
hosts:
- myExternalHostname.something
但是 运行 是否可以包含在 values.yaml 中?
values.yaml
文件不受 golang 插值。如果您需要动态内容,您需要更新 templates
目录中的文件(受 golang 插值),或使用另一种机制生成 values.yaml
内容
在这种特定情况下,您可能会发现 yaml 锚点很有用:
myApp:
externalHostName: &externalHostName myapp.example.com
theIngressOrWhatever:
hosts:
- *externalHostName
我正在重构一个 helm chart,我想输入一些从 deployment.yaml
到 values.yaml
的值,这个值是
hosts:
- {{ include "myApp.externalHostName" . | quote }}
但它给了我错误
[ERROR] values.yaml: unable to parse YAML: error converting YAML to
JSON: yaml: invalid map key: map[interface {}]interface {}{"toJson
include \"myApp.externalHostName\" . | quote":interface {}(nil)}
[ERROR] templates/: cannot load values.yaml: error converting YAML to
JSON: yaml: invalid map key: map[interface {}]interface {}{"toJson
include \"myApp.externalHostName\" . | quote":interface {}(nil)}
如果我只使用它就可以了
hosts:
- myExternalHostname.something
但是 运行 是否可以包含在 values.yaml 中?
values.yaml
文件不受 golang 插值。如果您需要动态内容,您需要更新 templates
目录中的文件(受 golang 插值),或使用另一种机制生成 values.yaml
内容
在这种特定情况下,您可能会发现 yaml 锚点很有用:
myApp:
externalHostName: &externalHostName myapp.example.com
theIngressOrWhatever:
hosts:
- *externalHostName