How do I load multiple templated config files into a helm chart?

前端 未结 3 829
执念已碎
执念已碎 2020-12-28 20:56

So I am trying to build a helm chart.

in my templates file I\'ve got a file like:

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-map
data:
{         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 21:29

    include all files from directory config-dir/, with {{ range ..:

    my-configmap.yaml:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: my-configmap
    data:
      {{- $files := .Files }}
      {{- range $key, $value := .Files }}
      {{- if hasPrefix "config-dir/" $key }} {{/* only when in config-dir/ */}}
      {{ $key | trimPrefix "config-dir/" }}: {{ $files.Get $key | quote }} {{/* adapt $key as desired */}}
      {{- end }}
      {{- end }}
    

    my-deployment.yaml

    apiVersion: apps/v1
    kind: Deployment
    ...
    spec:
      template:
        ...
        spec:
          containers:
            - name: my-pod-container
              ...
              volumeMounts:
                - name: my-volume
                  mountPath: /config
                  readOnly: true # is RO anyway for configMap
          volumes:
            - name: my-volume
              configMap:
                name: my-configmap
                # defaultMode: 0555 # mode rx for all
    

提交回复
热议问题