Hostpath volume not mounting on kubernetes running on Docker-desktop for windows

3/4/2021

I am running kubernetes on Docker-desktop for windows. I am connecting to the cluster from my WSL. all my pods are running correctly. I am trying to mount a volume on my jupyterlab (pod) using hostpath. below is my config

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jupyter
  labels:
    app: jupyter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jupyter
  template:
    metadata:
      labels:
        app: jupyter
    spec:
      containers:
      - name: jupyter
        image: jupyter:1.1
        ports:
        - containerPort: 8888
        securityContext:
          runAsNonRoot: true
          runAsUser: 1000
        volumeMounts:
          - name: mydir
            mountPath: /notebooks
      volumes:
        - name: mydir
          hostPath:
            # directory location on host
            path: /home/<myuser>/data
            # this field is optional
            type: DirectoryOrCreate

The pod starts without any issues. but i dont see the notbooks which i have kept in my hostpath onto my jupyter labs and vice versa( if i save a notebook in jupyter lab it does not get saved to my hostpath).

i followed the tutorial on https://kubernetes.io/docs/concepts/storage/volumes/#hostpath

i want to point out that i am using the @FROM jupyter/datascience-notebook:python-3.7.6" as my docker image.

i tried mounting /home/jovyan/ but it was giving me access related errors while starting the pod. so i reverted back to "/notebooks"

-- Seeker
docker
jupyter-notebook
kubernetes
kubernetes-pod

1 Answer

3/4/2021

It looks like an issue with how the path is being written on Windows, I see the issue reported in the references below.

Solution:

  • If your file is in say C: drive, it should be converted to the below
/host_mnt/c/path/to/my/folder
  • If the above does not work you may want to remove the "type: DirectoryOrCreate" and retry.

References: https://github.com/kubernetes/kubernetes/issues/59876#issuecomment-628955935 https://github.com/docker/for-win/issues/1703#issuecomment-366701358 .

-- DBSand
Source: StackOverflow