Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes persistent volume on Docker Desktop (Windows)

I'm using Docker Desktop on Windows 10. For the purposes of development, I want to expose a local folder to a container. When running the container in Docker, I do this by specifying the volume flag (-v).

How do I achieve the same when running the container in Kubernetes?

like image 775
Røye Avatar asked Jan 07 '19 11:01

Røye


People also ask

How Kubernetes works under the hood with Docker desktop?

Kubernetes normally pulls images from a registry, which would mean we would have to push and pull the image we have built after every change. Docker Desktop removes this friction by using dockershim to share the image cache between the Docker engine and Kubernetes.

Can enable Kubernetes in Docker desktop?

Enable KubernetesFrom the Docker Dashboard, select the Setting icon, or Preferences icon if you use a macOS. Select Kubernetes from the left sidebar. Next to Enable Kubernetes, select the checkbox. Select Apply & Restart to save the settings and then click Install to confirm.


2 Answers

You should use hostpath Volume type in your pod`s spec to mount a file or directory from the host node’s filesystem, where hostPath.path field should be of following format to accept Windows like paths:

  • /W/fooapp/influxdb
  • //W/fooapp/influxdb
  • /////W/fooapp/influxdb

Please check this github issue explaining peculiarities of Kubernetes Volumes on Windows. I assume also that you have enabled Shared Drives feature in your Docker for Windows installation.

like image 66
Nepomucen Avatar answered Sep 18 '22 02:09

Nepomucen


Using k8s 1.21.5 the following type of path worked for me:

/run/desktop/mnt/host/c/PATH/TO/FILE

Digging through this github issue helped me resolve which path to use: https://github.com/kubernetes/kubernetes/issues/59876

like image 29
darophi Avatar answered Sep 21 '22 02:09

darophi