Helm - Configmap - Read and update the file name

8/6/2021

I have the application properties defined for each environment inside a config folder.

config/
application-dev.yml
application-dit.yml
application-sit.yml

When i'm trying to deploy the application in dev, i need to create configmap by considering the applicaiton-dev.yml with a name application.yml.

When i'm trying to deploy the application in dit i need to create configmap by considering the application-dit.yml. But the name of the file should be always application.yml inside the configmap.

Any suggestions?

-- user16605649
helmfile
kubernetes

1 Answer

9/3/2021

When using helm to manage projects, different values.yaml files are generally used to distinguish between different environments (development/pre-release/online).

Suppose your configmap file is as follows:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ $.Values.cm.name }}
data:
  application.yml : |-
    {{ $.Files.Get {{ $.Values.cm.path }} | nindent 4 }}

In dev, define values-dev.yaml file

cm:
  name: test
  path: config/application-dev.yml

When you install the chart in dev, you can use the following command:

helm install test . -f values-dev.yaml


In dit, define values-dit.yaml file

cm:
  name: test
  path: config/application-dit.yml

When you install the chart in dit, you can use the following command:

helm install test . -f values-dit.yaml

-- z.x
Source: StackOverflow