Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mount local directory into pod in minikube

I am running minikube v0.24.1. In this minikube, I will create a Pod for my nginx application. And also I want to pass data from my local directory.

That means I want to mount my local $HOME/go/src/github.com/nginx into my Pod

How can I do this?

apiVersion: v1 kind: Pod metadata:   name: nginx spec:   containers:   - image: nginx:0.1     name: nginx     volumeMounts:     - mountPath: /data       name: volume   volumes:   - name: volume     hostPath:       path: /data 
like image 651
Abu Hanifa Avatar asked Jan 31 '18 05:01

Abu Hanifa


People also ask

How do I mount a file in Kubernetes pod?

So, basically, in Kubernetes, we can inject (mount) file into a container. In my case, I will mount a config file of my application into my docker containers. To do this, I can use the Kubernetes ConfigMap and Volumes, it allows us to inject configuration files into our docker application containers.


2 Answers

You can't mount your local directory into your Pod directly.

First, you need to mount your directory $HOME/go/src/github.com/nginx into your minikube.

$ minikube start --mount-string="$HOME/go/src/github.com/nginx:/data" --mount 

Then If you mount /data into your Pod using hostPath, you will get you local directory data into Pod.

There is another way

Host's $HOME directory gets mounted into minikube's /hosthome directory. Here you will get your data

$ ls -la /hosthome/go/src/github.com/nginx 

So to mount this directory, you can change your Pod's hostPath

hostPath:   path: /hosthome/go/src/github.com/nginx 
like image 129
Shahriar Avatar answered Sep 19 '22 03:09

Shahriar


I tried out aerokite's solution, but found out that I had to pass --mount as well as --mount-string "local-path:minikube-path" to mount a directory in minikube.

minikube start --mount-string ${HOME}/go/src/github.com/nginx:/data --mount. Spent some time figuring this out.

like image 27
K.S. Avatar answered Sep 23 '22 03:09

K.S.