1

In Kubernetes, I have the following section in deployment.yaml. I am using ConfigMap and I want to set the path dynamically based on the pod metadata or label or env variable in pod. Does ConfigMap support setting path dynamically?

spec:
                  volumes:
                    - name: configmap
                      configMap:
                        name: devconfig
                        items:
                          - key: config
                            path: $(ENVIRONMENT)
                        defaultMode: 420
developthou
  • 343
  • 1
  • 10
  • Does this answer your question? [Does application.yml support environment variables?](https://stackoverflow.com/questions/23027315/does-application-yml-support-environment-variables) – duppydodah Nov 17 '21 at 23:39
  • Also, I think it would be ${ENVIRONMENT} if what you are doing is supported – duppydodah Nov 17 '21 at 23:41
  • I have updated the description to explain what I am trying to solve. – developthou Nov 17 '21 at 23:53
  • Unfortunately no as the problem is to use the property of the pod to set the path. ConfigMap isn’t tied to any pod so this might not be possible. Let’s say the pod is in dev env, I want path to be called dev but in other to do that we need to be able to read the property of the pod – developthou Nov 19 '21 at 12:34

2 Answers2

1

This is call substitution which kubectl does not support out of the box. However, you can easily achieve what you want by using envsubst command which will substitute $ENVIRONMENT in your yaml with the the environment variable set in your current shell.

gohm'c
  • 13,492
  • 1
  • 9
  • 16
1

As an alternative to envsubst, that was absolutely correct answered by @gohm's, you may wanna try to use combination of job, that will check your configmap and pass proper values to your path.

Take a look: Kubernetes: use environment variable/ConfigMap in PersistentVolume host path

Vit
  • 7,740
  • 15
  • 40