How to Create a Configmap dynamically from a file

6/18/2018

I can create config map from a property file and use the same config files inside the POD. However, I don't want to use the configmap created in past and supplied with the helmchart. Rather in the helmchart values.yaml i want to provide a file name from where the config map will be created dynamically ..

Any suggestions/examples are welcome .

Thanks in advance - Tutai

-- Tutai Dalal
configmap
kubernetes
pod

1 Answer

6/18/2018

See if the approach described in kubernetes/charts issue 1310 works for you.

I suggest that we allow for overriding the name of the ConfigMap that gets mounted to the persistent volume.
That way, the parent chart could create, and even make templates for, these ConfigMaps.

For example values.yaml could have the following fields added:

## alertmanager ConfigMap entries
##
alertmanagerFiles:
  # ConfigMap override where full-name is {{.Release.Name}}-{{.Values.alertmanagerFiles.configMapOverrideName}}
  configMapOverrideName: ""
...

## Prometheus server ConfigMap entries
##
serverFiles:
  # ConfigMap override where full-name is {{.Release.Name}}-{{.Values.serverFiles.configMapOverrideName}}
  configMapOverrideName: ""
...

You can see the implementation of that issue in commit 2ea7764, as an example of override.


This differs from a file approach, where you create a new config map and replace the old one:

kubectl create configmap asetting --from-file=afile \
        -o yaml --dry-run | kubectl replace -f -

See "Updating Secrets and ConfigMaps" as an example.

-- VonC
Source: StackOverflow