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.



podvolume.yaml

apiVersion: v1
kind: Pod
metadata:
  name: demopod-volume
spec:
  containers:
  - image: nginx
    name: test-container
    volumeMounts: # this is new
    - mountPath: /data  # dir on container
      name: first-volume # match volume name
  volumes:
  - name: first-volume # volume name
    hostPath:
      # 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

Docker volumes on Windows WSL2

Docker Desktop is very useful developers tool.

And when running on Windows, optimally it should be on WSL2, 
that is a full Linux kernel embedded into windows.

And while the system works very well, it is still slightly different than Linux or Mac

WSL2 filesystem is visible from Windows

from windows explorer
\\wsl$\docker-desktop

From command prompt (i.e. PowerShell)

# see docker volumes
docker volume ls

# see WSL2 dirs/volumes
wsl -l -v

# list docker volume dirs in Windows
dir
 Directory: \\wsl$\docker-desktop-data\data\docker\volumes

# see contenet of docker volume
cd myvolume\data
dir Directory: \\wsl$\docker-desktop-data\data\docker\volumes\myvolume\_data Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 11/5/2022 2:55 PM network ----- 10/2/2022 5:21 PM 306 group ----- 11/5/2022 2:55 PM 0 hostname ----- 11/5/2022 2:55 PM 0 hosts ----- 10/1/2022 5:34 PM 118 localtime l---- 11/5/2022 2:55 PM 12 mtab -> ----- 10/2/2022 5:21 PM 340 passwd ----- 11/5/2022 2:55 PM 0 resolv.conf ----- 10/24/2022 8:08 PM 136 shadow

windows subsystem for linux - Where are Docker volumes located when running WSL using Docker Desktop? - Stack Overflow






cement / concrete usage: China vs. US

How China used more cement in 3 years than the U.S. did in the entire 20th Century - The Washington Post


A stunning statistic about China and concrete | Bill Gates