1. template 使用模板
define 操作允许我们在模板文件中创建一个命名模板,语法如下:
现在我们将模板嵌入到了已有的配置映射中,然后使用 template 包含进来:
{{- define "mychart.labels" }}
  labels:
    generator: helm
    date: {{ now | htmlDate }}
{{- end }}使用 template
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
  {{- template "mychart.labels" }}
data:
  myvalue: "Hello World"
  {{- range $key, $val := .Values.favorite }}
  {{ $key }}: {{ $val | quote }}
  {{- end }}当模板引擎读取该文件时,它会存储 mychart.labels 的引用直到 template "mychart.labels" 被调用。 然后会按行渲染模板,因此结果类似这样:
# Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: running-panda-configmap
  labels:
    generator: helm
    date: 2016-11-02
data:
  myvalue: "Hello World"
  drink: "coffee"
  food: "pizza"