How to access PersistentVolume files on docker-for-desktop? How to access PersistentVolume files on docker-for-desktop? docker docker

How to access PersistentVolume files on docker-for-desktop?


Thanks to @aman-tuladhar and some hours lost on the internet I've found out that you just need to make sure storageClassName is set for you PersistentVolume and PersistentVolumeClaim.

As per documentation if you want to avoid that Kubernetes dynamically generetes PersistentVolumes without considering the one you statically declared, you can just set a empty string " ".

In my case I've set storageClassName: manual.

PersistentVolume

kind: PersistentVolumemetadata:  name: wordpress-volumespec:  # ...  storageClassName: manual  hostPath:    path: /tmp/wordpress-volume

PersistentVolumeClaim

kind: PersistentVolumeClaimmetadata:  name: wordpress-volume-claimspec:  storageClassName: manual  # ...

This works out of the box with docker-for-desktop cluster (as long as mountPath is set to a absolute path).

References:


In case of MacOS and Kubernetes inside Docker for Mac. How to find a real location of dir-based local volume into VM

1) Create a new PersistentVolume with unique path:

blablabla.yml:

kind: PersistentVolumeapiVersion: v1metadata:  name: blablablaspec:  storageClassName: manual  capacity:    storage: 1G  accessModes:    - ReadWriteMany  hostPath:    path: "/mnt/blablabla"

kubectl apply -f blablabla.yml

2) Log into VM:

screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty# then press Enter

3) Find your volume:

find / -name blablabla/containers/services/docker/rootfs/mnt/blablabla # <= got it!/containers/services/docker/tmp/upper/mnt/blablabla

4) Exit from screen: Ctrl-a k y, Detach from screen: Ctrl-a d

Note

Sometimes you have a chance to get a broken screen session, it seems like a garbaged stdout with messed symbols, stdin still works fine. In that case, try to terminate all screen sessions and reconnect to the first one. Or just restart you docker for mac.


First this you need to remember is that Kubernetes is running on minikube cluster.minikube itself run on Virtual Machine. So that path won't be on you host machine, rather it is the path in Virtual Machine.

But with minikube we have easy way to do this. First you have to mount host directory to minikube.

(If you are using cloud providers you will have some way to create a storage. For GCE you have gcePersistentDisk)

minikube mount /path/to/dir/to/mount:/vm-mount-path

Now

kind: PersistentVolumemetadata:  name: wordpress-volumespec:  # ...  hostPath:    path: /vm-mount-path

If you create this resource this should save file in your host machine.

Follow this minikube documentation for more detail