kubernetes: Invalid Error: .container.volumes: hostPath type check failed: "not a directory"
What happened: I received an error that type check failed on hostPath, that it is not a directory, even though it is.
What you expected to happen: I did not expect to receive this error since the host path I passed is indeed a directory.
How to reproduce it (as minimally and precisely as possible):
Simply pass any host path and set type: Directory
Anything else we need to know?:
This is just a bad error. When I removed the type check, everything works fine. And it mounts a directory as expected.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 24 (4 by maintainers)
Commits related to this issue
- Remove hostPath type The issue in https://github.com/kubernetes/kubernetes/issues/83125 was encountered when trying to use /opt/rke/etc/kubernetes/ssl as the hostPath. Removing this resolves it. — committed to aiyengar2/charts by aiyengar2 4 years ago
- Remove hostPath type The issue in https://github.com/kubernetes/kubernetes/issues/83125 was encountered when trying to use /opt/rke/etc/kubernetes/ssl as the hostPath. Removing this resolves it. — committed to aiyengar2/charts by aiyengar2 4 years ago
- Remove hostPath type The issue in https://github.com/kubernetes/kubernetes/issues/83125 was encountered when trying to use /opt/rke/etc/kubernetes/ssl as the hostPath. Removing this resolves it. — committed to aiyengar2/charts by aiyengar2 4 years ago
- Remove hostPath type The issue in https://github.com/kubernetes/kubernetes/issues/83125 was encountered when trying to use /opt/rke/etc/kubernetes/ssl as the hostPath. Removing this resolves it. — committed to aiyengar2/charts by aiyengar2 4 years ago
I had the same issue using minikube and managed to solve it by starting minikube with --mount and --mount-string flags
I got the exact same error as you showed.
In my case, the issue was the folder defined in volume hostPath was not created. Once the folder was created in the worker node server, the issue was addressed.
I facing the same issue and it’s take 3 days. finally i solved by adding :
No it doesn’t work correctly. If we remove the type file it doesn’t give the error but it also doesn’t mount the directory which exists on the host. When i go into the directory on the pod, it is empty.
I am able to reproduce this issue using the csi-cinder-plugin manifest here: https://github.com/kubernetes/cloud-provider-openstack/blob/master/manifests/cinder-csi-plugin/cinder-csi-nodeplugin.yaml#L95-L98
yields
but I can verify the directory exists on the host machine
I am running Kubernetes on CentOS7, running on OpenStack. Removing
type: Directory(defaulting to DirectoryOrCreate) is a workaround that works for me, but this doesn’t appear to always be working as intended.I believe that directory is created by cloud-init, if that’s relevant.
A solution that worked for me…
Following the advice seen elsewhere, attempted to use a
/data/directory on the HOST MACHINE. When specifyingtype: Directoryfor the hostPath pv this would fail, as seen on this thread. Upon removing thetype: Directoryrestriction pods would successfully start, but then as noted by others changes to the mount path inside the pod were NOT reflected in the host (macOS) environment.As required, we can modify the “shared files” in Docker Desktop (Settings -> Resources -> Shared Files) and, following the advice seen elsewhere attempt to share our HOST MACHINE
/data/directory with Docker. Thenminikube delete ; minikube start --mount-string="/data:/data" --mount– however, going into a terminal on the container and performingcd /data; touch x; ls -alshows a file namedxis created inside/data/directory within the minikube container, but/data/on the HOST MACHINE remains empty. This, of course, is before even involving a hostPath pv via Minikube!Trying again,
minikube delete ; minikube start --mount-string="/data:/test"– then back into terminal andls -al /to see that there are both/data/and/test/at the volume root. Take note, as this highlights the problem. Nowcd /test/ ; touch x ; ls -aland seexfile is created in/test/within the minikube container, in the HOST MACHINE/data/also see thatxis created.The problem is the bind mount from Docker is not applied to the existing
/data/in the container image. It doesn’t matter what directory names you use on the HOST MACHINE this doesn’t seem to work as described.The reason
type: Directoryfails is because/data/does not bind to your mount as specified on the CLI, and, the expected directories obviously do not exist. The reasontype: DirectoryOrCreate(or removal oftype:) appears to work is because the/data/directory exists, and, the path specified within thehostPathspec is successfully created by minikubes hostPath implementation. The obvious problem is that/data/isn’t bound to the HOST MACHINE by docker as is expected (because/data/already exists within the minikube container image!), and therefore is not retained outside of the minikube container.Other notes:
I do not use virtualbox for VM on macOS (unnecessary dependency.)
This problem was present whether I used
gRPC FUSEorVirtioFSin Docker engine.MY ADVICE TO OTHER MINIKUBE USERS
/data/as bind path, use something unique that will avoid collision with minikube project, in my case i have gone with/d34db33f/– lel./data/dir Fx.:minikube start --mount-string="/data:/d34db33f"/data/on the HOST MACHINE i createmy-subfolder/path: /d34db33f/my-subfolderandtype: Directory/data/my-subfolder– i achieve parity between HOST MACHINE and POD environment./data/on HOST MACHINE as they are created within minikube container.Alternatively, don’t bind to
/data/and instead bind to specific sub-paths under/data/for use in your pv specs – yes, it’s more work, and it’s not something I want to be dealing with either… but in theory a mount string such as “/data/foo:/data/foo” would work as expected and is probably why minikube container image has a/data/in the first place. The flaw with this approach is the obvious restriction that once the minikube container is created in Docker engine new/different mount paths cannot be specified, making it a frustrating approach.Hope this helps others, i doubt this is OS/Platform/Docker/Minikube specific but have provided all versions I have in use anyway, I suspect this has been plaguing people over all versions for several years because the root cause was not well understood, and if anyone understood it they very, VERY poorly explained it. OP was 2019, it is now 2023.
👍
I’m trying to figure out why this issue was closed. It appears to be a real bug.
This issue should be reopened unless it is being tracked elsewhere.
@ruizmarlon I actually think I was wrong, I forgot I commented here. I was using microk8s and I needed to set the kubelet folder path to the one in snap since microk8s is a snap. Maybe it’s a real fix for you but just want to give you a heads up.
^ @stephen304 adding those directories worked like magic. Was using k0s & ceph-rook for my experiment. Thanks!!!
I just had this issue and fixed it by creating the 2 folders referenced in the error. Took me a while to find the right logs:
Yeah you have to remove the type field and it’s works 😃
Le sam. 9 mai 2020 à 02:23, Mithil Patel notifications@github.com a écrit :