How to mount a Host folder in minikube VM

Viewed 3269

I have a use case where I need a Docker container under kubernetes to access a hostPath. I'm using minikube, and the container is able to access a folder in the minikube VirtualBox VM. But I can't figure out how to get it to access a folder on the host itself.

I do these commands on the host to create /opt/foo for sharing in the VM:

$ sudo touch /opt/foo/FOO
$ ls /opt/foo
FOO
$ minikube mount -v 5 /opt/foo:/opt/foo
Mounting /opt/foo into /opt/foo on the minikubeVM
This daemon process needs to stay alive for the mount to still be accessible...
ufs starting

In another window I look in the minikube VM

$ minikube ssh -- sudo ls -la /opt/foo
total 0
drwxrwxr-x 2 root root 0 Jun  1 14:44 .
drwxr-xr-x 5 root root 0 Jun  1 14:44 ..

Is there another step needed to make the files in that directory accessible?

FYI - use case is a container process creating files that a host process is harvesting. Thus I do not want to use nfs or PersistentVolumes. Host is Centos7. minikube version: v0.19.0.

2 Answers

Just to generalize the great solution by Leo:

ip r g $(minikube ip)|awk '{print $3}'|head -n1|xargs sudo ufw allow in on
sudo ufw reload

This gets the minikube ip, looks up the interface and adds that to firewall rules.

Hope that helps anyone. And thanks Leo.

Related