embeding conf files into helm chart embeding conf files into helm chart kubernetes kubernetes

embeding conf files into helm chart


If the content of the files is static then you could create a files directory in your chart at the same level as the templates directory (not inside it) and reference them like:

kind: ConfigMapmetadata:  name: splunk-master-configmapdata:  {{ (.Files.Glob "files/indexes.conf").AsConfig | indent 2 }}  {{ (.Files.Glob "files/otherfile.conf").AsConfig | indent 2 }}# ... and so on

Where this would break down is if you want to be able to reference the values of variables inside the files so that the content is controlled from the values.yaml. If you want to expose each value individually then there's an example in the helm documentation using range. But I think a good fit or your case is what the stable/mysql chart does. It has a ConfigMap that takes values as strings:

{{- if .Values.configurationFiles }}apiVersion: v1kind: ConfigMapmetadata:  name: {{ template "mysql.fullname" . }}-configurationdata:{{- range $key, $val := .Values.configurationFiles }}  {{ $key }}: |-{{ $val | indent 4}}{{- end }}{{- end -}}

And the values.yaml allows both the files and their content to be set and overridden by the user of the chart:

# Custom mysql configuration files used to override default mysql settingsconfigurationFiles:#  mysql.cnf: |-#    [mysqld]#    skip-name-resolve#    ssl-ca=/ssl/ca.pem#    ssl-cert=/ssl/server-cert.pem#    ssl-key=/ssl/server-key.pem

It comments out that content and leaves it to the user of the chart to set but you could have defaults in the values.yaml.

You would only need tpl if you needed further flexibility. The stable/keycloak chart lets the user of the chart create their own configmap and point it into the keycloak deployment via tpl. But I think your case is probably closest to the mysql one.

Edit: the tpl function can also be used to take the content of files loaded with Files.Get and effectively make that content part of the template - see How do I load multiple templated config files into a helm chart? if you're interested in this