<p>How to use ConfigMap for <code>$LOCAL_IP_DB</code> variable declared in below section as input for another variable declared?  <code>$LOCAL_IP_DB</code> is a generic key defined inside <code>db-secret configmap</code>, but there is another environment variable which needs it? How to make it work?</p>
<pre><code>spec:
      containers:
        - env:
            - name: LOCAL_IP_DB
              valueFrom:
                configMapKeyRef:
                    name: db-secret
                    key: LOCAL_IP_DB
            - name: LOG_Files
              value: \\${LOCAL_IP_DB}\redis\files\
</code></pre>

infotechie1
<p>The key is using: <code>$()</code> instead of <code>${}</code></p>
<p>example-pod.yaml:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: example
spec:
  containers:
  - name: example
    image: bash
    args: [printenv]
    env:
    - name: LOCAL_IP_DB
      valueFrom:
        configMapKeyRef:
          name: db-secret
          key: LOCAL_IP_DB
    - name: LOG_FILES
      value: \$(LOCAL_IP_DB)\redis\files\
</code></pre>
<p>example-configmap.yaml:</p>
<pre><code>apiVersion: v1
data:
  LOCAL_IP_DB: 192.168.0.1
kind: ConfigMap
metadata:
  name: db-secret
</code></pre>
<p>test:</p>
<pre><code>controlplane $ kubectl apply -f example-pod.yaml -f example-configmap.yaml 
controlplane $ kubectl logs example | grep 192
LOCAL_IP_DB=192.168.0.1
LOG_FILES=\192.168.0.1\redis\files\
</code></pre>
<p>You can find more information about this function here: <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config" rel="nofollow noreferrer">link</a></p>
<p>Note, if you want to manage secrets <a href="https://kubernetes.io/docs/concepts/configuration/secret/" rel="nofollow noreferrer">Secret</a> is the recommended way to do that.</p>
