<p>I have an application in a container which reads a YAML file which contains data like </p>

<pre><code>              initializationCount=0
              port=980
</code></pre>

<p>Now that I want to remove those hard coded values inside the application and get them out of the container. Hence I created a configMap with all configuration values. I used the config map keys as environmental variables while deploying the pod.</p>

<p>My issue is that, If I want to use these environment variables in my yaml file like </p>

<pre><code>            initializationCount=${iCount}
            port=${port}
</code></pre>

<p>The API which reads this YAML file throws number format Exception since the env variables are always strings. I do not have control over the API which reads my yaml file.</p>

<p>I have tried  </p>

<pre><code>            initializationCount=!!int ${iCount} 
</code></pre>

<p>but it does not work.</p>

<p>Rather than pulling in the configmap values as environment variables, try mounting the configmap as a volume at runtime. </p>

<p>The configmap should have one key which is the name of your YAML file. the value for that key should be the contents of the file. </p>

<p>This data will be mounted to the container's filesystem when the pod initializes. That way your app will read the config YAML the same way it has been, but the values will be externalized in the configmap.</p>

<p>Something like this:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: my-app
      image: my-app:latest
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config
  volumes:
    - name: config-volume
      configMap:
        name: app-config
</code></pre>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  config.yaml: |
    initializationCount=0
    port=980
</code></pre>

<p>Kubernetes docs <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#populate-a-volume-with-data-stored-in-a-configmap" rel="nofollow noreferrer">here</a></p>
