Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:
{{ Do something here to load up a set of files | indent 2 }}

I have another directory in my chart: configmaps where a set of json files, that themselves will have templated variables in them:

a.json
b.json
c.json

Ultimately I'd like to be sure in my chart I can reference:

volumes:
   - name: config-a
     configMap:
       name: config-map
       items:
       - key: a.json
         path: a.json
like image 687
Nathan Feger Avatar asked Dec 01 '17 14:12

Nathan Feger


People also ask

Do Helm chart has Yaml files in its package?

yaml is used by many of the Helm tools, including the CLI. When generating a package, the helm package command will use the version that it finds in the Chart. yaml as a token in the package name. The system assumes that the version number in the chart package name matches the version number in the Chart.

How do you pass values to Helm chart?

You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.

What is TPL file in Helm?

These files are used to store partials and helpers. In fact, when we first created mychart , we saw a file called _helpers. tpl . That file is the default location for template partials.

What is appVersion in Helm chart?

Chart versions and appVersions Each Helm chart has the ability to define two separate versions: The version of the chart itself ( version field in Chart. yaml ). The version of the application contained in the chart ( appVersion field in Chart.


1 Answers

I had same problem for a few weeks ago with adding files and templates directly to container.

Look for the sample syntax:

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-configmap-{{ .Release.Name }}
  namespace: {{ .Release.Namespace }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  nginx_conf: {{ tpl (.Files.Get "files/nginx.conf") . | quote }}
  ssl_conf: {{ tpl (.Files.Get "files/ssl.conf") . | quote }}
  dhparam_pem: {{ .Files.Get "files/dhparam.pem" | quote }}
  fastcgi_conf: {{ .Files.Get "files/fastcgi.conf" | quote }}
  mime_types: {{ .Files.Get "files/mime.types" | quote }}
  proxy_params_conf: {{ .Files.Get "files/proxy_params.conf" | quote }}

Second step is to reference it from deployment:

  volumes:
  - name: {{ $.Release.Name }}-configmap-volume
    configMap:
      name:nginx-configmap-{{ $.Release.Name }}
      items:
        - key: dhparam_pem
          path: dhparam.pem
        - key: fastcgi_conf
          path: fastcgi.conf
        - key: mime_types
          path: mime.types
        - key: nginx_conf
          path: nginx.conf
        - key: proxy_params_conf
          path: proxy_params.conf
        - key: ssl_conf
          path: ssl.conf 

It's actual for now. Here you can find 2 types of importing:

  • regular files without templating
  • configuration files with dynamic variables inside

Please do not forget to read official docs: https://helm.sh/docs/chart_template_guide/accessing_files/

Good luck!

like image 89
Oleg Mykolaichenko Avatar answered Sep 22 '22 19:09

Oleg Mykolaichenko