Install k8s Minikube on top of KVM on Debian 9
You want to do some Kubernetes on your laptop? You probably know that the solution is named Minikube.
Last time I tried to have minikube running on a debian, I had hard time finding the right way to do it, there’s so many outdated documentations out there that it’s easy to get lost.
My goal is to make Jenkins 2 running on Kubernetes and make use of Kubernetes scalability features to start as many containers our builds need so that we stop waiting for builds forever. I’ll write another article about that later.
My workmates now need to work on this Jenkins + k8s stuff and they probably don’t want to struggle as much as I did last time.
So I decided to make the Web messier and even more outdated by writing my own “it works today” article about the Debian 9 + k8s + KVM combo.
Enjoy (and feel free to contribute if there are things that could be enhanced).
The first step is to make KVM and libvirt to work. It’s quite simple, the first step is to install the right packages and put your user in the right groups (remember that you needed a new session for new group membership to apply) :
$ apt install qemu-kvm libvirt-clients libvirt-daemon-system
$ adduser myuser libvirt
$ adduser myuser libvirt-qemu
Then, as myuser
$ virsh — connect qemu:///system list — allId Name State
— — — — — — — — — — — — — — — — — — — — — — — — —
It returns an empty list and no error. That was easy. The hardest part was to find that documentation, right?
Next step is to make use of Minikube. Minikube is a tool to bootstrap dev environments easily.
It first requires to install
kubectl, the command for managing a k8s instance.
Did I already said I hate curling random binary from the internet? So, I searched for a more distribution-friendly solution and found this way :
$ apt install -y apt-transport-https
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
$ cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
$ apt update
$ apt install -y kubectl
Now you can install minikube :
$ curl -LO https://github.com/kubernetes/minikube/releases/download/v0.25.0/minikube_0.25-0.deb
$ dpkg — force-depends -i minikube_0.25–0.deb
You probably noticed the
—force-dependsoption? minikube documentation states that you can use it either on top of virtualbox or kvm. But the package manifest forces virtualbox dependency. I don’t like being forced to install virtualbox so I tell dpkg that I don’t want to honor this package’s dependencies.
You probably share my opinion, right? Then, just do the same.
Now, we unfortunately reach the random curl point, sorry. We need to install the right driver for docker-machine to use kvm and I didn’t found any workaround. I’m glad I install all that on a laptop dedicated to these tests !
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 && chmod +x docker-machine-driver-kvm2 && sudo mv docker-machine-driver-kvm2 /usr/bin/
Well, for some reason, minikube requires
default libvirt network to be activated, so let’s do that :
$ virsh — connect qemu:///system net-start default
Finally, we can launch k8s :
$ minikube start — vm-driver kvm2
After some time, it says it’s ready. At this point, k8s is running on top of kvm and you can access the web dashboard.
$ minikube dashboard
If everything goes well, you should have the k8s opened in your browser now, ready to deploy services at scale.
But wait, a howto is not finished without a hello-world of some kind, right?
Here is how you do hello-world on k8s :
$ kubectl run hello-minikube — image=k8s.gcr.io/echoserver:1.4 — port=8080
$ kubectl expose deployment hello-minikube — type=NodePort
$ curl $(minikube service hello-minikube — url) -d hello world
It runs a container with an http server echoing input request data as a response, then it exposes the service and finally you curl it.
That’s amazing, isn’t it?
You can find more information regarding minikube on https://kubernetes.io/docs/getting-started-guides/minikube/ .