<p>I've figured out the syntax to mount a volume (Kubernetes YAML):</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  ...
spec:
  containers:
    - name: php
      volumeMounts:
        - mountPath: /app/db_backups
          name: db-backups
          readOnly: true
  volumes:
    - hostPath:
        path: /mnt/c/Users/Mark/PhpstormProjects/proj/db_backups
        type: DirectoryOrCreate
      name: db-backups
</code></pre>
<p>And the volume does show when I drop into a shell:</p>
<pre><code>kubectl --context docker-desktop exec --stdin --tty deploy/app-deployment-development -cphp -nmyns -- /bin/bash
</code></pre>
<p>But the <code>db_backups</code> directory is empty, so I guess the volume is backed by nothing -- it's not finding the volume on my Windows host machine.</p>
<p>I've tried setting the host path like <code>C:\Users\Mark\PhpstormProjects\proj\db_backups</code> but if I do that then my Deployment fails with a <code>CreateContainerError</code>:</p>
<blockquote>
<p>Error: Error response from daemon: invalid volume specification: 'C:\Users\Mark\PhpstormProjects\proj\db_backups:/app/db_backups:ro'</p>
</blockquote>
<p>So I guess it doesn't like the Windows-style filepath.</p>
<p>So what then? If neither style of path works, how do I get it to mount?</p>

mpen
<p>From <a href="https://stackoverflow.com/questions/66985465/kubernetes-how-to-correctly-mount-windows-path-in-wsl2-backed-environment">here</a> it is clear that, for <strong>WSL2</strong> we need to mention the specific path before we are actually giving the path we desired in the host machine.</p>
<p>In your file you are giving like <code>path: /mnt/c/Users/Mark/PhpstormProjects/proj/db_backups</code> but you need to mention the path like this <code>path: /run/desktop/mnt/host/path_of_directory_in_local_machine</code>. The key is we need to mention <code>/run/desktop/mnt/host/</code> before we are going to give the actual path to the directory.</p>
<p>You gave the <code>type: DirectoryOrCreate</code> in the above file, so that is creating an <strong>empty directory</strong> in the path you mentioned. Because it is not actually going to your desired path.</p>
<p>So try with this</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  ...
spec:
  containers:
    - name: php
      volumeMounts:
        - mountPath: /app/db_backups
          name: db-backups
          readOnly: true
  volumes:
    - hostPath:
        path: /run/desktop/mnt/host/c/Users/Mark/PhpstormProjects/proj/db_backups
#In my case tested with path: /run/desktop/mnt/host/d/K8-files/voldir
        type: DirectoryOrCreate
      name: db-backups
</code></pre>
<p>It worked in our case, we created a directory in <strong>'d'</strong> drive so we used this <code>path: /run/desktop/mnt/host/d/K8-files/voldir</code>. So try giving <code>/run/desktop/mnt/host/</code> before the actual path.</p>
<p>For more information refer this <a href="https://devpress.csdn.net/k8s/62ebfca589d9027116a0fe82.html" rel="nofollow noreferrer">Link</a></p>
