In the following article, we're using Minikube (v1.14.2) with Kubectl (1.19) running on Ubuntu 20.04.1 LTS.
The background to this problem is as follows:
You're using Minikube and you want to mount a local drive in a pod and that's it.
This should be fairly straightforward however it's not exactly. We'll cover a fully working example here.
The real issue is that we need to mount a local directory to a directory in Minikube and then mount that directory to a directory in the pod itself.
If we just follow an example for mounting a local directory in a pod in Kubernetes, when we have shell access to the pod and check the path, the directory will exist however it will be empty.
Reference #1 (Shahriar, specifically) explains the solution pretty closely however a fully working example is not provided.
The following pod configuration file should work but, as we'll see in a moment, it doesn't.
Here's an example of what the minikube start script might look like --- we need to change this in order to fix this issue.
minikube start --hyperv-virtual-switch "My Virtual Switch" --v=4
The following image demonstrates the problem inside the pod --- note the /etc/minimounted/ directory is empty whereas we're expecting the hello.txt file to be there.
Now let's take a look at a solution.
In order to make this work, we need to start Minikube with the following mount and mount-string options set:
minikube start --hyperv-virtual-switch "My Virtual Switch" --v=4 --mount --mount-string="/etc/minimount/:/minimounted/"
We have /etc/minimount/ mounted as /minimount/ in Minikube and when we run the nginx-minimounted pod the /minimount/ directory will be mounted as /etc/minimounted/ in the pod; we can see the directory contents in the image below.
And that's it for this article.
If you liked this article you may also like the following articles, also written by yours truly:
- Easily Install the Metrics Server on Minikube in 5 Steps
- Answers to Five Kubernetes CKAD Practice Questions (2020)
Please add comments below if you find an error with anything written here or have a question about this document.
- Mount local directory into pod in minikube
- MountVolume.SetUp failed for volume "mongo" : hostPath type check failed: /mongo/data is not a directory
- hostpath : MountVolume.SetUp failed for volume "test-volume" : hostPath type check failed: /data is not a directory
- Invalid Error: .container.volumes: hostPath type check failed: "not a directory"