Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MountVolume.SetUp failed for volume "mongo" : hostPath type check failed: /mongo/data is not a directory

I'm trying to configure a hostPath to launch Mongodb pod.

I have only one node of kubernetes v1.8.5 installed with rancher last stable version.

I have create folder /mongo/data and allow all permissions to all users. enter image description here

I'm able to run docker image perfectly with docker without sudo:

docker run --name some-mongo -v /mongo/data:/data/db mongo:3.2.1

But when I launch to kubernetes:

sudo kubectl create -f mongodb.yml

I get MountVolume.SetUp failed for volume "mongo" : hostPath type check failed: /mongo/data is not a directory

This is the mongodb.yml:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: mongo:3.2.1
    name: test-container
    volumeMounts:
    - mountPath: /data/db
      name: mongo
  volumes:
  - name: mongo
    hostPath:
      # directory location on host
      path: /mongo/data
      # this field is optional
      type: Directory

Any idea where I should looking for?

like image 244
TlmaK0 Avatar asked Feb 22 '18 12:02

TlmaK0


2 Answers

Changing type: Directory to type: DirectoryOrCreate works for me.

like image 108
Kevin Avatar answered Sep 22 '22 06:09

Kevin


If by any chance you are using minikube, then don't forget that minikube itself is a container. So hostPath points to a path in that container, not to a path on your host machine. You have to mount your PC path into the minikube container and then into the POD.

Example: minikube start --mount --mount-string="/host/path:/minikubeContainer/path"

like image 26
vladimirror Avatar answered Sep 22 '22 06:09

vladimirror