kubernetes: Error message misleading with hostPath volumes under Windows

/kind bug /sig windows

What happened:

I tried to setup a volume mount under windows, but got a misleading error message.

volumeMounts part:

        volumeMounts:
        - name: influxdb-storage
          mountPath: /var/lib/influxdb

volumes part:

      volumes:
      - name: influxdb-storage
        hostPath:
          path: D:/influxdb
          type: DirectoryOrCreate

Error message on kubernetes dashboard was:

Error received from daemon, Invalid mode for /var/lib/influxdb

What you expected to happen:

Better error message to explain the problem better, since as turned out, not the volumeMounts part was wrong, but the hostPath.path was in the wrong format. As a kubernetes newbie I was searching for solutions for the volumeMounts part, but did not find anything…

After I modified it to /D/influxdb everything worked like a charm.

How to reproduce it (as minimally and precisely as possible):

Create a kubernetes deployment under windows with a hostPath volume.

Anything else we need to know?:

Environment:

  • Kubernetes version:
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.2", GitCommit:"5fa2db2bd46ac79e5e00a4e6ed24191080aa463b", GitTreeState:"clean", BuildDate:"20018-01-18T10:09:24Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.2", GitCommit:"bdaeafa71f6c7c04636251031f93464384d54963", GitTreeState:"clean", BuildDate:"2
017-10-24T19:38:10Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration: N/A
  • OS (e.g. from /etc/os-release): Microsoft Windows [Version 10.0.16299.214]
  • Kernel (e.g. uname -a): N/A
  • Install tools: N/A
  • Others: N/A

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 45 (18 by maintainers)

Most upvoted comments

I came across this post after updating my Docker Desktop for Windows to version 3.3 using WSL2 integration. After several more hours of research, I came across the answer described here: https://stackoverflow.com/questions/62812948/volume-mounts-not-working-kubernetes-and-wsl-2-and-docker/63524931#63524931

What used to work as:

/C/path/to/file

Now works as:

/run/desktop/mnt/host/c/path/to/file

I hope this helps someone else who comes across this issue.

+1. Just hit this issue with a Windows host running a Linux pod on Docker for Windows. Changing from path: C:/foo/bar to path: /C/foo/bar solved it. Sadly, https://kubernetes.io/docs/getting-started-guides/windows/#volumes suggests it could have been path: "C:\\foo\\bar" which I found didn’t work. The feature works correctly, but the error message is very misleading. I’m glad I found this as the top result when searching for kubernetes hostPath Error: Error response from daemon: invalid mode:.

@juniormayhe We came across this after updating to docker-desktop 2.3.0.2. issue#1703 finally had the answer for us: Instead of:

/C/path/to/file

It works with:

/host_mnt/c/path/to/file

I can not find any official information on this but I hope this helps someone else who comes across this issue.

/run/desktop/mnt/host/c/path/to/file

Ok this works, thank you so much. but, where is this mount file exactly? I dont find any on my distro (Arch linux) or docker-desktop or docker-desktop-data entry?

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.

You can remote into the docker-desktop VM and see the /run/desktop/mnt/host/c mount point and folder structure by following the instructions (and discussion) at https://stackoverflow.com/a/62117039/11057678:

docker run -it --rm --privileged --pid=host justincormack/nsenter1

@attilah specify /D/influxdb will find c:\D\influxdb dir, if it does not exist, it will create a new dir as your specify type: DirectoryOrCreate I think you wan to use D:\influxdb in hostPath, right?, just use path: 'D:\influxdb'

/run/desktop/mnt/host/c/path/to/file

Ok this works, thank you so much. but, where is this mount file exactly? I dont find any on my distro (Arch linux) or docker-desktop or docker-desktop-data entry?

I’m wondering how you come to this conclusion. There are 2 nodes on the rancher, one linux and one windows. and I want to add persistent volumes to them. I can’t add it as hostpath. how do i do this? I’m a beginner, someone who knows, please guide me in detail.

/run/desktop/mnt/host/c/path/to/file

Ok this works, thank you so much. but, where is this mount file exactly? I dont find any on my distro (Arch linux) or docker-desktop or docker-desktop-data entry?

@attilah specify /D/influxdb will find c:\D\influxdb dir, if it does not exist, it will create a new dir as your specify type: DirectoryOrCreate I think you wan to use D:\influxdb in hostPath, right?, just use path: 'D:\influxdb'

I just do as below: path: /some/funny/loc type: DirectoryOrCreate Everything looks fine; I mean I got data consistency. But I can’t locate /some/funny/loc in my host. Where can I locate the ‘/some/funny/loc’?

But the issue is about the misleading error message, not that something does not work.

If Kubernetes under windows finds an invalid (in terms of windows) path specification, it should give the error message about THAT part, not the part within the container, which has nothing to do with it.