path for PersistentVolume in Kubernetes .yaml in Windows
I searched a lot because of every sample for Kubernetes is referring to paths for Unix/Macos. I found (don't remember where...) that a valid path for Windows should be the one in the sample path: /c/temp/data/db
With minikube, you can't mount your local directory into a PersistentVolume as you are trying.
Minikube creates a virtual machine with Linux and your cluster is running inside this Linux VM. That's why it can't see your files in your windows machine.
To be able to access your local directory into your minikube cluster you need to mount it into your minikube:
You have few options to achieve what you need. The best and easiest way is to start your minikube with the option --mount
. This option will mount C:/Users/ by default.
Example:
PS C:\WINDOWS\system32> minikube delete; minikube.exe start --vm-driver=virtualbox --mount
If you ssh into minikube Linux VM:
PS C:\WINDOWS\system32> minikube ssh _ _ _ _ ( ) ( ) ___ ___ (_) ___ (_)| |/') _ _ | |_ __/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)$$ df -h Filesystem Size Used Avail Use% Mounted on tmpfs 1.9G 489M 1.5G 26% / devtmpfs 987M 0 987M 0% /dev tmpfs 1.1G 0 1.1G 0% /dev/shm tmpfs 1.1G 17M 1.1G 2% /run tmpfs 1.1G 0 1.1G 0% /sys/fs/cgroup tmpfs 1.1G 4.0K 1.1G 1% /tmp /dev/sda1 17G 1.3G 15G 8% /mnt/sda1 /c/Users 181G 106G 76G 59% /c/Users
$ cd /c/Users/ $ pwd /c/Users
If you want\need to mount any other directory than C:/Users, take a look at minikube mount and/or --mount-string. You may face some issues with these option depending on your vm-driver.
After mounting your directory you can use it in you PersistentVolume refering to the Linux path that based on my examples it can be /c/Users/myname/myapp/db.
apiVersion: v1kind: PersistentVolumemetadata: name: mongo-pvspec: capacity: storage: 1Gi volumeMode: Filesystem accessModes: - ReadWriteOnce storageClassName: local-storage local: path: /c/Users/myname/myapp/db nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - docker-desktop
Please, let me know if my answer helped you to solve your problem.