3

I am looking to do local dev of an app that is running in Kubernetes on minikube. I want to mount a local directory to speed up development, so I can make code changes to my app (python) without rebuilding the container.

If I understand correctly, I have two out of the box options:

  1. 9P mount which is provided by minikube
  2. hostPath mount which comes directly from Kubernetes

What are the differences between these, and in what cases would one be appropriate over the other?

Dan Green-Leipciger
  • 3,776
  • 1
  • 19
  • 29

1 Answers1

5

9P mount and hostPath are two different concepts. You cannot mount directory to pod using 9P mount.

9P mount is used to mount host directory into the minikube VM.

HostPath is a persistent volume which mounts a file or directory from the host node's(in your case minikube VM) filesystem into your Pod.

Take a look also on types of Persistent Volumes: pv-types-k8s.

If you want to mount a local directory to pod:

First, you need to mount your directory for example: $HOME/your/path into your minikube VM using 9P. Execute command:

$ minikube start --mount-string="$HOME/your/path:/data"

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

Another solution:

Mount host's $HOME directory into minikube's /hosthome directory. Get your data:

$ ls -la /hosthome/your/path

To mount this directory, you have to just change your Pod's hostPath

hostPath:
  path: /hosthome/your/path

Take a look: minikube-mount-data-into-pod.

Also you need to know that:

Minikube is configured to persist files stored under the following directories, which are made in the Minikube VM (or on your localhost if running on bare metal). You may lose data from other directories on reboots.

More: note-persistence-minikube.

See driver-mounts as an alternative.

Dan Green-Leipciger
  • 3,776
  • 1
  • 19
  • 29
Malgorzata
  • 6,409
  • 1
  • 10
  • 27