<p>I know you can use ConfigMap properties as environment variables in the pod spec, but can you use environment variables declared in the pods spec inside the configmap?</p>

<p>For example:</p>

<p>I have a secret password which I wish to access in my configmap application.properties. The secret looks like so:</p>

<pre><code>apiVersion: v1
data:
  pw: THV3OE9vcXVpYTll==
kind: Secret
metadata:
  name: foo
  namespace: foo-bar
type: Opaque
</code></pre>

<p>so inside the pod spec I reference the secret as an env var. The configMap will be mounted as a volume from within the spec:</p>

<pre><code>    env:
      - name: PASSWORD
        valueFrom:
          secretKeyRef:
            name: foo
            key: pw
...
</code></pre>

<p>and inside my configMap I can then reference the secret value like so:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: application.properties
  namespace: foo-bar
data:
  application.properties: /
    secret.password=$(PASSWORD)
</code></pre>

<p>Anything I've found online is just about consuming configMap values as env vars and doesn't mention consuming env vars in configMap values.</p>

<p><strong>Currently it's not a Kubernetes Feature.</strong></p>

<p>There is a closed issue requesting this feature and it's kind of controversial topic because the discussion is ongoing many months after being closed:
<a href="https://github.com/kubernetes/kubernetes/issues/79224" rel="nofollow noreferrer">Reference Secrets from ConfigMap #79224</a></p>

<p>Referencing the closing comment:</p>

<blockquote>
  <p>Best practice is to not use secret values in envvars, only as mounted files. if you want to keep all config values in a single object, you can place all the values in a secret object and reference them that way.
  Referencing secrets via configmaps is a non-goal... it confuses whether things mounting or injecting the config map are mounting confidential values.</p>
</blockquote>

<p>I suggest you to read the entire thread to understand his reasons and maybe find another approach for your environment to get this variables.</p>

<hr>

<p><strong><em>"OK, but this is Real Life, I need to make this work"</em></strong></p>

<p>Then I recommend you this workaround:</p>

<p><strong><a href="https://stackoverflow.com/questions/50452665/import-data-to-config-map-from-kubernetes-secret">Import Data to Config Map from Kubernetes Secret</a></strong></p>

<p>It makes the substitution with a shell in the entrypoint of the container. </p>
