Home > Enterprise >  Substitute env variable in PATH in ConfigMap in Kubernetes
Substitute env variable in PATH in ConfigMap in Kubernetes

Time:11-19

In Kubernetes, I have the following section in deployment.yaml. I am using ConfigMap and I want to set the path dynamically. Does ConfigMap support setting path dynamically?

spec:
                  volumes:
                    - name: configmap
                      configMap:
                        name: devconfig
                        items:
                          - key: config
                            path: $(ENVIRONMENT)
                        defaultMode: 420

CodePudding user response:

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.

CodePudding user response:

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

  • Related