<p>I have an application in a container which reads certain data from a configMap which goes like this</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  application.yaml: |
        server:
          port: 8080
          host: 0.0.0.0

        ##
        ## UCP configuration.
        ## If skipped, it will default to looking inside of the connections.xml file.
        database:
            ApplicationDB:
                username: username
                password: hello123
</code></pre>

<p>Now I created a secret for the password and mounted as env variable while starting the container.</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: appdbpassword
type: Opaque
stringData:
  password: hello123
</code></pre>

<p>My pod looks like:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: {{ .Values.pod.name }}
spec:
  containers:
    - name: {{ .Values.container.name }}
      image: {{ .Values.image }}
      command: [ "/bin/sh", "-c", "--" ]
      args: [ "while true; do sleep 30; done;"]
      env:
      - name: password
        valueFrom:
          secretKeyRef:
            name: appdbpassword
            key: password
      volumeMounts:
      - name: config-volume
        mountPath: /app/app-config/application.yaml
        subPath: application.yaml
  volumes:
    - name: config-volume
      configMap:
        name: app-config
</code></pre>

<p>I tried using this env variable inside the configMap:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  application.yaml: |
        server:
          port: 8080
          host: 0.0.0.0

        ##
        ## UCP configuration.
        ## If skipped, it will default to looking inside of the connections.xml file.
        database:
            ApplicationDB:
                username: username
                **password: ${password}**
</code></pre>

<p>But my application is unable to read this password. Am I missing something here? </p>

<p>EDIT:</p>

<p>I cannot change the application.yaml to any other form as my server looks for application.yaml in source path. Do we have any way to use that environment variable in values.yaml(helm) file and use it in the configmap?</p>

Bhargav Behara
<p>your ${password} variable will not be replaced by its value as application.yaml is a static file. If you use this yaml file in some configuration then it is  possible that it will get replaced by its value.</p>

<p>consider a scenario where instead of application.yaml pass this file</p>

<pre><code>application.sh: |
       echo "${password}"
</code></pre>

<p>now go inside /app/app-config you will see application.sh file . And now do <code>sh application.sh</code> you will see the value of environment variable. </p>

<p>I hope this might clear your point.</p>
