In the process of building a new home lab virtual server, I decided to test out Kubernetes running on KVM. I have a new NUC server I am setting up and I installed CentOS 7 with the GUI server configuration. I installed the virtual host and client components to use it as a host dedicated to virtual machines.
After installing a test Linux VM to make sure everything is working, I decided to install Kubernetes Minikube. The Kubernetes documentation is excellent and has a lot of advice for selecting a solution or distribution type to use. It also has a good tutorial for a first test of “Hello World” Node.js app to run.
As is typical, there are usually some small problems to overcome in the process. Either with the differences in configuration of the host system or from problems introduced between the version in the docs and the version currently available. I experienced a few configuration issues that needed to be resolved. I also had a problem with the latest version of the docker kvm driver that was easy to work around by using an older version of the driver.
- Install CentOS 7
- Install KVM
- I chose to use the packages in installer
- It can also be setup after CentOS using yum
- Install docker kvm driver
- Install kubectl
- Install Minikube
- Hello Minikube Tutorial
Prepare host system for installation
I found that I needed to do a few things to the host for the install to work well. First was to make sure my user was configured correctly in the wheel group to be a sudoer.
I also switched to root user and used visudo to modify the path by adding “/usr/local/bin”. This is needed to be able to execute the Minikube command and also for it to find the docker kvm driver without specifying the path on the command line.
I also added my user ID to the libvirt group as shown in the docker driver instructions.
[mike@mb-nuc2 ~]$ sudo usermod -a -G libvirt $(whoami) [mike@mb-nuc2 ~]$ newgrp libvirt
Install Docker KVM Driver
Installing the driver.
When I used the steps in the driver install document Minikube would crash and show an error. I searched for the error message and found a bug report that matches the issue. I used the work around mentioned to install an older version of the driver.
Use this command to install the older version of the driver.
[mike@mb-nuc2 ~]$ sudo su curl -LO https://github.com/kubernetes/minikube/releases/download/v0.30.0/docker-machine-driver-kvm2 && sudo install docker-machine-driver-kvm2 /usr/local/bin/
Install using the yum package manager. The repository needs to get setup first. The text from the install page shows the commands to create the repo file using cat.
sudo cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg EOF
I did it as root as follows:
[mike@mb-nuc2 ~]$ sudo bash [sudo] password for mike: [root@mb-nuc2 mike]# cat <<EOF > /etc/yum.repos.d/kubernetes.repo > [kubernetes] > name=Kubernetes > baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 > enabled=1 > gpgcheck=1 > repo_gpgcheck=1 > gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg > EOF [root@mb-nuc2 mike]# yum install -y kubectl Loaded plugins: fastestmirror, langpacks Existing lock /var/run/yum.pid: another copy is running as pid 16068. Another app is currently holding the yum lock; waiting for it to exit... The other application is: PackageKit Memory : 29 M RSS (449 MB VSZ) Started: Sun Feb 17 21:28:49 2019 - 00:03 ago State : Sleeping, pid: 16068 Another app is currently holding the yum lock; waiting for it to exit... The other application is: PackageKit Memory : 43 M RSS (463 MB VSZ) Started: Sun Feb 17 21:28:49 2019 - 00:05 ago State : Sleeping, pid: 16068 Another app is currently holding the yum lock; waiting for it to exit... The other application is: PackageKit Memory : 43 M RSS (463 MB VSZ) Started: Sun Feb 17 21:28:49 2019 - 00:07 ago State : Sleeping, pid: 16068 Loading mirror speeds from cached hostfile * base: www.gtlib.gatech.edu * extras: mirror.wdc1.us.leaseweb.net * updates: mirror.wdc1.us.leaseweb.net kubernetes/signature | 454 B 00:00:00 Retrieving key from https://packages.cloud.google.com/yum/doc/yum-key.gpg Importing GPG key 0xA7317B0F: Userid : "Google Cloud Packages Automatic Signing Key <firstname.lastname@example.org>" Fingerprint: d0bc 747f d8ca f711 7500 d6fa 3746 c208 a731 7b0f From : https://packages.cloud.google.com/yum/doc/yum-key.gpg Retrieving key from https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg kubernetes/signature | 1.4 kB 00:00:00 !!! kubernetes/primary | 44 kB 00:00:00 kubernetes 314/314 Resolving Dependencies --> Running transaction check ---> Package kubectl.x86_64 0:1.13.3-0 will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================== Package Arch Version Repository Size ===================================================================================================================== Installing: kubectl x86_64 1.13.3-0 kubernetes 8.5 M Transaction Summary ===================================================================================================================== Install 1 Package Total download size: 8.5 M Installed size: 37 M Downloading packages: warning: /var/cache/yum/x86_64/7/kubernetes/packages/e3438a5f740b3a907758799c3be2512a4b5c64dbe30352b2428788775c6b359e-kubectl-1.13.3-0.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 3e1ba8d5: NOKEY Public key for e3438a5f740b3a907758799c3be2512a4b5c64dbe30352b2428788775c6b359e-kubectl-1.13.3-0.x86_64.rpm is not installed e3438a5f740b3a907758799c3be2512a4b5c64dbe30352b2428788775c6b359e-kubectl-1.13.3-0.x86_64.rpm | 8.5 MB 00:00:15 Retrieving key from https://packages.cloud.google.com/yum/doc/yum-key.gpg Importing GPG key 0xA7317B0F: Userid : "Google Cloud Packages Automatic Signing Key <email@example.com>" Fingerprint: d0bc 747f d8ca f711 7500 d6fa 3746 c208 a731 7b0f From : https://packages.cloud.google.com/yum/doc/yum-key.gpg Retrieving key from https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg Importing GPG key 0x3E1BA8D5: Userid : "Google Cloud Packages RPM Signing Key <firstname.lastname@example.org>" Fingerprint: 3749 e1ba 95a8 6ce0 5454 6ed2 f09c 394c 3e1b a8d5 From : https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : kubectl-1.13.3-0.x86_64 1/1 Verifying : kubectl-1.13.3-0.x86_64 1/1 Installed: kubectl.x86_64 0:1.13.3-0 Complete! [root@mb-nuc2 mike]# exit
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \ && chmod +x minikube sudo cp minikube /usr/local/bin
Make sure the minikube file and the driver file are in /usr/local/bin and that they both have execute permissions.
When running minikube you also need to specify the name of the driver to use. Note, the name is not the same as the file name.
minikube start --vm-driver=kvm2
Launching minikube for the first time (the first time after fixing all the issues)
[mike@mb-nuc2 ~]$ sudo minikube start --vm-driver=kvm2 😄 minikube v0.34.1 on linux (amd64) 🔥 Creating kvm2 VM (CPUs=2, Memory=2048MB, Disk=20000MB) ... 📶 "minikube" IP address is 192.168.39.196 🐳 Configuring Docker as the container runtime ... ✨ Preparing Kubernetes environment ... 💾 Downloading kubeadm v1.13.3 💾 Downloading kubelet v1.13.3 🚜 Pulling images required by Kubernetes v1.13.3 ... 🚀 Launching Kubernetes v1.13.3 using kubeadm ... 🔑 Configuring cluster permissions ... 🤔 Verifying component health ..... 💗 kubectl is now configured to use "minikube" 🏄 Done! Thank you for using minikube! [mike@mb-nuc2 ~]$
You can see the VMs get created and activity start in in Virtual Machine Manager.
Launching the dashboard gives some errors because I am using sudo as a regular user. Its OK, just cut and paste the URL into your browser.
[mike@mb-nuc2 ~]$ sudo minikube dashboard 🔌 Enabling dashboard ... 🤔 Verifying dashboard health ... 🚀 Launching proxy ... 🤔 Verifying proxy health ... 🎉 Opening http://127.0.0.1:44474/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ in your default browser... START /bin/firefox "http://127.0.0.1:44474/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/" Running without a11y support! Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /run/gdm/auth-for-mike-7ZfFZq/database which is owned by mike.) xdg-open: no method available for opening 'http://127.0.0.1:44474/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/' ❌ failed to open browser: exit status 3
Hello Minikube Tutorial
Going through the tutorial is straight forward and provides some basic details about adimistration of a container.
Setup the hello node tutorial.
sudo kubectl create deployment hello-node --image=gcr.io/hello-minikube-zero-install/hello-node
Create a service to expose the hello world web app.
sudo kubectl expose deployment hello-node --type=LoadBalancer --port=8080
[mike@mb-nuc2 ~]$ sudo kubectl expose deployment hello-node --type=LoadBalancer --port=8080 service/hello-node exposed [mike@mb-nuc2 ~]$
[mike@mb-nuc2 ~]$ sudo kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-node LoadBalancer 10.107.138.132 <pending> 8080:30603/TCP 41s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 38m [mike@mb-nuc2 ~]$
sudo minikube service hello-node
[mike@mb-nuc2 ~]$ sudo minikube service hello-node 🎉 Opening kubernetes service default/hello-node in default browser... START /bin/firefox "http://192.168.39.196:30603" Running without a11y support! Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /run/gdm/auth-for-mike-7ZfFZq/database which is owned by mike.) xdg-open: no method available for opening 'http://192.168.39.196:30603' [mike@mb-nuc2 ~]$
Open a new browser window and paste in the URL from the output. It shows the “hello world” text from the Node.js app.
Now is a good time to use the dashboard to see some details about the hello world app deployment.
You can also view and download the logs from the app that show the requests from the browser.
To cleanup and remove the hello world node:
kubectl delete service hello-node kubectl delete deployment hello-node
The kubernetes tutorial and documentation is excellent. There were a few glitches but I think that is to be expected given the differences in version and operating systems. They were fairly simple to solve and in the end everything worked great.
I plan to expand on using kubernetes with Node.js. I have some development projects that I think will be ideal for this setup.