<p>Is it possible in Kubernetes to mount a file from a ConfigMap into an directory that already has other files?  E.g.</p>
<p>Base image filesystem:</p>
<pre><code>/app/
  main/
    main.py
    test.py
</code></pre>
<p>ConfigMap contains one file, mounted.py, which should be mounted in /app/main/ alongside main.py and test.py.</p>
<p>Desired filesystem after deployment:</p>
<pre><code>/app/
  main/
    main.py
    test.py
    mounted.py
</code></pre>
<p>What I have seen so far is that the ConfigMap is mounted to a new directory, so the closest I have come is like this:</p>
<pre><code>/app/
  main/
    main.py
    test.py
    mounted/
      mounted.py
</code></pre>
<p>If I mount the ConfigMap to /app/main, then it clobbers the existing files from the base image.  E.g.</p>
<pre><code>/app/
  main/
    mounted.py
</code></pre>
<p>Is there a good way to inject a single file like that?  (Actually multiple files in my real use case.)  I would prefer not to have separate directories for everything that will be injected by the ConfigMaps, since it deviates from the standard program architecture.</p>

Rusty Lemur
<p>Use <code>subPath</code>:</p>
<pre><code>volumeMounts:
  - name: config
    mountPath: /app/main/mounted.py
    subPath: mounted.py
</code></pre>
<p>The <code>mountPath</code> shows where it should be mounted, and <code>subPath</code> points to an entry inside the volume.</p>
<p>Please be aware of the limitation: when using subPath the configMap updates won't be reflected in your file. See the <a href="https://kubernetes.io/docs/concepts/storage/volumes/#configmap" rel="nofollow noreferrer">official documentation</a> for details.</p>
