<p>I am trying to map a configMap in JSON format to my docker image in Kubernetes
I am using config npm package to fetch the configurations.</p>
<p>The idea is that I will have a file development.json in /config directory from there the config package will pick it up. This all works in localhost. The name of the config file is the same as the NODE_ENV variable, which I am also setting in the deployment.yaml</p>
<p>I am using default namespace</p>
<p>This is the beginning of the configMap (I can see it is created in google kubernetes)</p>
<p>I am running ls is the config directory to see if the development.json file has been mounted but it is not. I want the /config to be replaced and only contain the development.json file</p>
<p>I have also tried with the subPath parameter but same result</p>
<p>What am I doing wrong ? Should I see in the events that the configMap is mounted. There is no log of that except when I delete the configMap and try to do the mount, so I figure that the mounting is happening</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: config-development
  namespace: default
data:
  development.json: |
    {
      &quot;production&quot;: false,
</code></pre>
<p>Here is the mount:</p>
<pre><code>volumes:
        - name: config-volume
          configMap:
            name: config-development
      containers:
        - name: salesforce-compare-api
          image: XXXX
          command: [&quot;ls&quot;]
          args: [&quot;config&quot;, &quot;-la&quot;]
          imagePullPolicy: Always
          env:
          - name: NODE_ENV
            value: &quot;development&quot;
          volumeMounts:
          - name: config-volume
            mountPath: /config/development.json
</code></pre>

<p>Usually, when the configmap cannot be mounted, the pod will not even start. So the fact that it started, shows that its mounted.</p>
<p>In any case, your volumeMounts looks problematic.</p>
<pre><code>volumeMounts:
  - name: config-volume
    mountPath: /config/development.json
</code></pre>
<p>This lead to the full configmap being mounted into a folder named development.json, while you actually only want to mount the one file.</p>
<p>Use a <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer">subpath</a> for this.</p>
<pre><code>volumeMounts:
  - name: config-volume
    mountPath: /config/development.json
    subPath: development.json
</code></pre>
<p>That said, if you config folder inside the container is otherwise empty, you can also drop the subpath and mount the configmap to the /config dir, since it will not override anything important.</p>
<pre><code>volumeMounts:
  - name: config-volume
    mountPath: /config
</code></pre>
