How best to have files on volumes in Kubernetes using helm charts? How best to have files on volumes in Kubernetes using helm charts? kubernetes kubernetes

How best to have files on volumes in Kubernetes using helm charts?


Since you are dealing with json a good example to follow might be the official stable/centrifugo chart. It defines a ConfigMap that contains a config.json file:

data:  config.json: |-{{ toJson .Values.config| indent 4 }}

So it takes a config section from the values.yaml and transforms it to json using the toJson function. The config can be whatever you want define in that yaml - the chart has:

config:  web: true  namespaces:  - name: public    anonymous: true    publish: true...

In the deployment.yaml it creates a volume from the configmap:

      volumes:      - name: {{ template "centrifugo.fullname" . }}-config        configMap:          name: {{ template "centrifugo.fullname" . }}-config

Note that {{ template "centrifugo.fullname" . }}-config matches the name of the ConfigMap.

And mounts it into the deployment's pod/s:

        volumeMounts:        - name: "{{ template "centrifugo.fullname" . }}-config"          mountPath: "/centrifugo"          readOnly: true

This approach would let you populate the json config file from the values.yaml so that you can set different values for different environments by supplying custom values file per env to override the default one in the chart.

To handle the license.dat you can add an extra entry to the ConfigMap to define an additional file but with static content embedded. Since that is a license you may want to switch the ConfigMap to a Secret instead, which is a simple change of replacing the word ConfigMap for Secret in the definitions. You could try it with ConfigMap first though.