Among many guides on how to start with Kubernetes and Minikube here is most consise one I'd recommend: https://github.com/dysinger/learn-minikube
Disclaimer: This guide was tested with minikube 0.16.0 and due to this issue getting volume mounting with KVM was impossible. Althoug it was tested with development version at the time and above issue was no longer was a problem, so it should be fixed by now.
$ minikube start
$ minikube dashboard # to get to the UI
In order for kubernetes nodes be able to pull from a private docker registry kubernetes need to be authenticated with it, which can be achieved by creating a secret:
$ kubectl create secret docker-registry my-docker-registry \
--docker-server="my.example.net" \
--docker-username="DOCKER_USER" \
--docker-password="DOCKER_PASSWORD" \
--docker-email="DOCKER_EMAIL"
secret "my-docker-registry" created.
Despite that VirtualBox automatically mounts host's /home
folder as
/hosthome
inside of a minikube node, it is mounted with permissions that do
not allow reading/writing/executing to anybody that is not root inside the
node. Interestingly enough, neither permissions nor ownership can be changed
after a share has been mounted. Therefore, a few manual steps required in order
to be able to mount a path from the machine into the container throigh minikube:
-
After minikube has started open VirtualBox and add a share.
-
Now that the share is inside our minikube node we can mount it:
$ minikube ssh 'sudo mkdir /media/my-share && sudo mount -t vboxsf -o gid=$(id -u),uid=$(id -g),rw my-share /media/my-share'
After all this /media/my-share
can be further mounted into a pod using the
usual hostPath
volume type.
If using VirtualBox is not an option then we can use KVM instead.
At the time of writing there was a bug in implementation of minikube that caused it to hang if it was stopped and started back up again, therefore development version of minikube had to be downloaded from: https://storage.googleapis.com/minikube-builds/1050/minikube-linux-amd64 or a version > 0.16.0, if one is available. Also vendored driver need to be selected:
$ minikube config set use-vendored-driver true
Further it goes like that:
- Starting minikube with KVM
$ minikube start --vm-driver=kvm
Starting local Kubernetes cluster...
Kubectl is now configured to use the cluster.
- With KVM it is not possible to add a passthrough filesystem while the VM is running, we need to stop it first:
$ minikube stop
Stopping local Kubernetes cluster...
Machine stopped.
- Add a passthrough filesystem to our VM:
$ virsh attach-device minikube kvm-volume.xml --config
Were content of kms-volume.xml
:
<filesystem type='mount' accessmode='passthrough'>
<driver type='path' wrpolicy='immediate'/>
<source dir='/path/to/my-share/'/>
<target dir=my-share'/>
</filesystem>
-
Alternatively passthrough filesystem can be added using
virt-manager
GUI:- Open Virtual Machine Manager
- Open
minikube
VM (should be in Shutoff state) - Open "Information" -> "Add Hardware" -> "Filesystem"
- Select "Passthrough".
- "Browse" -> "Browse Local"
- "Finish"
-
Start minikube back up:
$ minikube start --vm-driver=kvm
Starting local Kubernetes cluster...
Kubectl is now configured to use the cluster.
- Once it's up and running we can mount the shared folder within
minikube
node:
$ minikube ssh 'sudo mkdir /media/my-share/ && sudo mount -t 9p -o trans=virtio,version=9p2000.L,rw my-share /media/my-share'
Only now this folder /media/my-share
can be further mounted into a pod running
a container using hostPath
volume type.