Saturday, November 05, 2022

Kubernetes volume on Docker Desktop on Windows

 Kubernetes persistent volume on Docker Desktop (Windows) - Stack Overflow

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

The folder mount for /run/desktop/mnt/host/c does not exist on the distro you installed in WSL2 - on that WSL2 distro, the mount point to your C:\ drive is the more obvious /mnt/c.

Realize that Kubernetes and Docker are not installed in your installed WSL2 distro. Instead, Docker Desktop for Windows creates its own WSL2 VM called docker-desktop and installs Docker and Kubernetes on that VM. Then Docker Desktop for Windows installs the docker and kubectl CLIs on your WSL2 distro (and also on your Windows machine) and configures them all to point to the Docker and Kubernetes instances it created on the docker-desktop VM. This docker-desktop VM is hosting Docker and Kubernetes and also contains the /run/desktop/mnt/host/c mount point to your Windows C:\ drive and that can be used by your containers to persist data.


apiVersion: v1
kind: Pod
  name: demopod-volume
  - image: nginx
    name: test-container
    volumeMounts: # this is new
    - mountPath: /data  # dir on container
      name: first-volume # match volume name
  - name: first-volume # volume name
      # path: /mydata # dir on host, linux/mac
      path: /run/desktop/mnt/host/c/mydata # windows c:\mydata dir
      type: DirectoryOrCreate

# create host dir
mkdir c:\mydata

# create pod
k apply -f .\pod-volume.yaml
pod/demopod-volume created

No comments: