Skip to content

Running a local Kubernetes cluster with Minikube on KVM

License

Notifications You must be signed in to change notification settings

idvoretskyi/minikube-kvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Running Kubernetes locally on Ubuntu Linux with Minikube and KVM

Minikube is a cross-platform, community-driven Kubernetes distribution, which is targeted to be primarily used in the local environments. It deploys a single-node cluster, which is an excellent option for having a simple Kubernetes cluster up&running on localhost.

Minikube is designed to be used as a virtual machine (VM), and the default VM runtime of Minikube is VirtualBox. At the same time, extensibility is one of the critical benefits of Minikube, so it's possible to use it without VirtualBox, but with other drivers.

At the same time, QEMU/KVM is a Linux-native virtualization solution, which may offer more benefits comparing to VirtualBox. Specifically, it's way more natural to use KVM on the headless GNU/Linux server.

Also, VirtualBox and KVM can't be used simultaneously, so if you are already running any KVM workloads on some machine, and willing to run Minikube there as well, using the KVM minikube driver is a preferred way to go.

In this guide, we'll focus on running Minikube with the KVM driver on Ubuntu 18.04 LTS.

Disclaimer

This is not an official minikube guide. You may find detailed information on running and using Minikube on it's official webpage, where different use cases, operating systems, environments, etc. are covered. Instead, the purpose of this guide - to provide some easy and clear guidelines on running Minikube with KVM on a Linux.

Prereqs

  • Any Linux you like (in this tutorial we'll use Ubuntu 18.04 LTS, and all the instructions below are applicable to it. If you prefer using a different Linux distribution, please check out the relevant documentation, or make this tutorial better and submit a PR 😉)
  • Installed and properly configured libvirt and QEMU-KVM
  • Kubernetes CLI (kubectl) for operating the Kubernetes cluster

QEMU/KVM and libvirt installation

NOTE: skip if already installed

Before we proceed, we have to verify if our host can run KVM-based virtual machines. This can be easily checked with the kvm-ok tool, available on Ubuntu.

sudo apt install -y cpu-checker && sudo kvm-ok

If you receive the following output after running kvm-ok, you can use KVM on your machine (otherwise, please check out your configuration):

$ sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

Now let's install KVM and libvirt (and add our current user to the libvirt group to grant sufficient permissions:

sudo apt install -y libvirt-clients libvirt-daemon-system qemu-kvm \
    && sudo usermod -a -G libvirt $(whoami) \
    && newgrp libvirt

kubectl (Kubernetes CLI) installation

NOTE: skip if already installed

To have an ability to manage the Kubernetes cluster, we have to install kubectl, the Kubernetes CLI tool.

The natural way to install it - download the pre-built binary and move it to the directory under the $PATH.

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \
    && sudo install kubectl /usr/local/bin

Alternatively, it can be installed as a snap package. This means that your snapd has to be installed and configured. On Ubuntu 18.04+ (as well as on other Ubuntu flavors) snapd is available by default.

sudo snap install kubectl --classic

snap_kubectl.png

Minikube installation

Minikube KVM driver installation

VM driver is an essential requirement for the Minikube local deployment. As we've agreed to use KVM as a Minikube driver in this tutorial, let's install the KVM driver with the following command:

curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \
    && sudo install docker-machine-driver-kvm2 /usr/local/bin/

Minikube installation

Now let's install Minikube itself:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
    && sudo install minikube-linux-amd64 /usr/local/bin/minikube

Verify the Minikube installation

Before we proceed, we have to verify if Minikube is correctly installed. The simplest way to do it - check the minikube status.

minikube status

minikube_status.png

To use the KVM2 driver:

Now let's run the local Kubernetes cluster with Minikube and KVM:

minikube start --vm-driver kvm2

minikube_start_--vm-driver_kvm2.png

Set KVM2 as a default VM driver for Minikube

If KVM is a single driver for Minikube on our machine, it's way more convenient to set it as a default driver and run Minikube with less command-line arguments. The following command sets KVM driver as a default one:

minikube config set vm-driver kvm2

So now let's run minikube as usual:

minikube start

minikube_start.png

Verify the Kubernetes installation

Let's check out if the Kubernetes cluster is up and running:

kubectl get nodes

kubectl_get_nodes.png

Now let's run a simple sample app (nginx in our case):

kubectl create deployment nginx --image=nginx

Also, check out if the Kubernetes pods are correctly provisioned

kubectl get pods

kubectl_nginx.png

Next steps

Now the Kubernetes cluster on a local machine with Minikube and KVM is adequately set up and configured.

To proceed, you may check out the Kubernetes tutorials on the project website:

Also, it's worth it checking the "Introduction to Kubernetes" course by The Linux Foundation/Cloud Native Computing Foundation, available for free on EDX: