<p>I have the following ConfigMap in my Kubernetes cluster that contains the <code>web.config</code> for my application there is a different one per environment so I would like to volume mount the ConfigMap to <code>web.config</code> in the pod.</p>
<p><strong>ConfigMap</strong>:</p>
<pre class="lang-yaml prettyprint-override"><code>kind: ConfigMap 
apiVersion: v1 
metadata:
  name: stars-website-data-config
  namespace: stars-website
data:
  config: |-
    &lt;?xml version=&quot;1.0&quot;?&gt;
    &lt;configuration&gt;
      ...
    &lt;/configuration&gt;
</code></pre>
<p><strong>Deployment</strong>:</p>
<pre class="lang-yaml prettyprint-override"><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: stars-website-data
  namespace: stars-website
spec:
  template:
    spec:
      containers:
        - name: stars-website-data
          ...
          volumeMounts:
            - name: config
              mountPath: C:\STARS.Website.Data
      volumes:
        - name: config
          configMap:
            name: stars-website-data-config
            items:
            - key: config
              path: web.config
</code></pre>
<p>This seems to do what I want it to do but it replaces all the other files and folder in that directory.</p>
<pre><code>PS C:\STARS.Website.Data&gt; ls 


    Directory: C:\STARS.Website.Data 


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        5/14/2021  10:55 AM                ..2021_05_14_09_55_42.624339347
d----l        5/14/2021  10:55 AM                ..data
-a---l        5/14/2021  10:55 AM              0 web.config


PS C:\STARS.Website.Data&gt; cat .\web.config
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;configuration&gt;
        &lt;configSections&gt;
</code></pre>
<p>If I try to use the <code>subPath</code> value like:</p>
<pre class="lang-yaml prettyprint-override"><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: stars-website-data
  namespace: stars-website
spec:
  template:
    spec:
      containers:
        - name: stars-website-data
          ...
          volumeMounts:
            - name: config
              mountPath: C:\STARS.Website.Data\web.config
              subPath: web.config
      volumes:
        - name: config
          configMap:
            name: stars-website-data-config
            items:
            - key: config
              path: web.config
</code></pre>
<p>I am getting the following error:</p>
<pre><code>Error: Error response from daemon: invalid volume specification: 'c:\var\lib\kubelet\pods\ddfe6b07-4bff-42fe-ad3b-a02add00fbbf\volumes\kubernetes.io~configmap\config\web.config:C:\STARS.Website.Data\web.config:ro': invalid mount config for type &quot;bind&quot;: source path must be a directory
</code></pre>

Ross
<p>When configMap is mounted as volume then it will delete all the files which were previously present in the mount path, this is expected behaviour. Please refer caution section in this <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">link</a>.</p>
<p>With respective to your subpath configuration, there is a limitation in bind mounting files directly for windows based container, please refer this <a href="https://github.com/moby/moby/issues/30555" rel="nofollow noreferrer">discussion</a>.  The preferred approach is directory mounting for windows based container, you can create separate empty directory and you can mount your configmap to that directory which might be quick and straight forward solution.</p>
<p>This <a href="https://artisticcheese.wordpress.com/2021/05/02/circumventing-windows-containers-limitation-on-volume-mounts/" rel="nofollow noreferrer">link</a> has got workaround solution which might be useful for you.</p>
<p>There is one major disadvantage of using either subpath configuration or workaround solution given in the above link is whenever you update your configmap it would not automatically update the project key.</p>
<p>Thanks,</p>
