Mounting a hostPath volume to Windows host from Kubernetes

I am running Docker (edge version 1.37) with Kubernetes on my local machine to do some development work. If I am just running docker from the command line on my machine i can spin up a container and mount a volume like so:

docker run -v D:\myhost\mydirectory:/myvolume ... 

However, when creating a deployment to Kubernetes, is it possible to mount the same volume to a container running inside a pod? For example, the following deployment fails to mount because i assume kubernetes is itself running inside a container and does not recognize my system path D:\myhost\path

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: myDeployment
spec:
  ...
  containers:
   ...
    volumeMounts:
      - name: mymount
        mountPath: /etc/mymount
    ports:
      ...
  volumes:
    - name: mymount
      hostPath:
        path: D:\myhost\path
        type: Directory

Is there some magic I can do to achieve this?

Thanks!

1 Like

I would also very much would like to know this.

I wanted to use Kubernetes to setup a development environment, but not being able to mount Windows folders into the containers would make it unusable.

Also I’m running into this issue:

Someone could help me find documentation on this subject since the little I have been able to find is for Linux, and I would like to be able to try it in my work environment. Thank you.
By the way, I have the same problem but I think it must be the semantics that I am using in the manifesto. Some example would come more than good. Thank you!!

I’m also finding it hard to locate what the solution is to this. Does anyone have the instructions to get it working?

Hey, did you get to the bottom of this i’m also trying to do the same thing. I’ve also tried specifying the path based on the WSL path of e.g.
hostpath:
path: /mnt/c/directory/etc

but no joy. Anyone get this working?

/mnt/c/* worked for me in creating a postgres mount. I did create the C:/k8s/postgres directory beforehand - maybe that makes the difference?

kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgres-pv-volume  # Sets PV's name
  labels:
    type: local  # Sets PV's type to local
    app: postgres
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi # Sets PV Volume
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt/c/k8s/postgres"
1 Like

This (i.e., using WSL path syntax) also worked for me. I had a directory on the Windows host at D:\k3dvolume.

So in the PersistentVolume.hostPath key I specified /mnt/d/k3dvolume