Helm-在values.yaml中对变量进行模板化 [英] Helm - Templating variables in values.yaml

查看:810
本文介绍了Helm-在values.yaml中对变量进行模板化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将来自values.yaml内的映射的变量模板化为最终的Kubernetes ConfigMap YAML.

I'm trying to template variables from a map inside the values.yaml into my final Kubernetes ConfigMap YAML.

我已阅读 https://github.com/helm/helm/issues/2492 https://helm.sh/docs/chart_template_guide/,但似乎无法找到答案.

I've read through https://github.com/helm/helm/issues/2492 and https://helm.sh/docs/chart_template_guide/ but can't seem to find an answer.

在某些情况下,这大致就是我想做的:

For some context, this is roughly what I'm trying to do:

values.yaml

config:
  key1: value
  key2: value-{{ .Release.Name }}

configmap.yaml

kind: ConfigMap
data:
  config-file: |
    {{- range $key, $value := .Values.config }}
    {{ $key }} = {{ $value }}
    {{- end }}

其中所需的输出将是:

头盔模板--name v1 mychart/

kind: ConfigMap
data:
  config-file: |
    key1 = value
    key2 = value-v1

我尝试使用模板函数和流水线进行了一些变体,但无济于事:

I've tried a few variations using template functions and pipelining, but to no avail:

{{ $key }} = {{ tpl $value . }}
{{ $key }} = {{ $value | tpl . }}
{{ $key }} = {{ tpl $value $ }}

推荐答案

设法使用以下语法解决此问题:

Managed to solve this using the following syntax:

configmap.yaml

kind: ConfigMap
data:
  config-file: |
    {{- range $key, $value := .Values.config }}
    {{ $key }} = {{ tpl ($value | toString) $ }}
    {{- end }}

这篇关于Helm-在values.yaml中对变量进行模板化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆