<p>I have a configmap created. I have added data as a key-value pair in configmap</p>
<pre><code>data:
  EXTERNAL_CONFIG_FILE: /user/app/api/config
</code></pre>
<p>I need to use this variable to set a mount path in deployment</p>
<pre><code>-  name: config-properties-volume-mnt
   mountPath: {{ $EXTERNAL_CONFIG_FILE }}
</code></pre>
<p>I am getting  undefined variable &quot;$EXTERNAL_CONFIG_FILE&quot; while deploying. <strong>I do not want to define this variable in values.yaml.</strong> Is there a way where I can use this variable defined in configmap in deployment?</p>

Krishna Upadhyay
<p><strong>It's not possible to dynamically define any parameter on a manifest</strong>, you have to use the Helm or Kustomize</p>
<p>Or else you can use the <strong>sed</strong> to replace the <strong>Text</strong> in manifest simply</p>
<p>You can not use this way, <strong>configmap</strong> and <strong>secret</strong> are normally to inject the variables or file into the POD not at declare step.</p>
<pre><code>-  name: config-properties-volume-mnt
   mountPath: {{ $EXTERNAL_CONFIG_FILE }}
</code></pre>
<p>if you have helm chart keeping details into the <code>vaules.yaml</code> is the only option.</p>
<p><strong>Subpath method :</strong></p>
<p>You can use the subpath to achieve, with <strong>subpath</strong> you can use the environment: <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath-expanded-environment" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath-expanded-environment</a></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  containers:
  - name: container1
    env:
    - name: EXTERNAL_CONFIG_FILE
      value: /user/app/api/config
    image: busybox:1.28
    command: [ &quot;sh&quot;, &quot;-c&quot;, &quot;while [ true ]; do echo 'Hello'; sleep 10; done | tee -a /logs/hello.txt&quot; ]
    volumeMounts:
    - name: workdir1
      mountPath: /logs
      # The variable expansion uses round brackets (not curly brackets).
      subPathExpr: $(EXTERNAL_CONFIG_FILE)
  restartPolicy: Never
  volumes:
  - name: workdir1
    hostPath:
      path: /var/log/pods
</code></pre>
<p>Instead of <strong>env</strong> used in the above example you can use the <strong>configmap</strong></p>
