We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To run Minikube on KVM (Libvirt)

Learn how to – How To run Minikube on KVM (Libvirt).

Minikube is a tool developed to help you run a single cluster of Kubernetes on your local machine. Minikube works by starting a single node kubernetes cluster locally for purposes of development and testing. It packages and configures a Linux VM, Docker and all Kubernetes components, optimized for local development. In this guide you’ll learn to run Minikube on KVM Virtualization environment.

Similar:

Minikube supports Kubernetes features such as:

  • NS
  • NodePorts
  • ConfigMaps and Secrets
  • Dashboards
  • Container Runtime: Docker, CRI-O, and containerd
  • Enabling CNI (Container Network Interface)
  • Ingress
  • PersistentVolumes of type hostPath

Most Minikube setups available online are for VirtualBox as a hypervisor for the VM. If you’re a frequent visitor of my blog, you must have noticed I’m a big fan of KVM. So this guide is for those who want to run Minikube but on KVM.

For VirtualBox users, follow the guide How to Install Minikube on Ubuntu

Setup Requirements

To run Minikube on KVM, you need to install some libraries and drivers required for communication with the Virtualization layer. These are:

  • Docker machine – This is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with docker-machine commands
  • Docker Machine KVM2:  This is a plugin driver for docker-machine on KVM.
  • Qemu and Libvirt – Hypervisor and Virtualization API Library
  • Minikube and kubectl

Step 1: Installing KVM – Libvirt and Qemu

Refer to our guide in the link below:

Step 2: Install Docker-machine

Installation of docker machine will vary from one distribution to another. But when you have docker community repository added to your System, you can install docker-machine from OS package manager. Our guide on installing Docker has a step of adding the repository:

You can also take a look at Official Docker machine page.

Step 3: Download Minikube

You need to download the minikube binary. I will put the binary under /usr/local/bin directory since it is inside $PATH.

wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube-linux-amd64
sudo mv minikube-linux-amd64 /usr/local/bin/minikube

Check version installed.

$ minikube version
minikube version: v1.30.1
commit: 08896fd1dc362c097c925146c4a0d0dac715ace0

For Arch Linux users, you can install minikube from AUR:

$ yay -Sy minikube-bin

Step 4: Install kubectl

We need kubectl which is a command-line tool used to deploy and manage applications on Kubernetes.

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

Give the file executable bit and move to a location in your PATH.

chmod +x kubectl
sudo mv kubectl  /usr/local/bin/
kubectl version -o json 

Confirm the version of kubectl installed.

$ kubectl version -o json  --client
{
  "clientVersion": {
    "major": "1",
    "minor": "26",
    "gitVersion": "v1.26.1",
    "gitCommit": "8f94681cd294aa8cfd3407b8191f6c70214973a4",
    "gitTreeState": "clean",
    "buildDate": "2023-01-18T15:58:16Z",
    "goVersion": "go1.19.5",
    "compiler": "gc",
    "platform": "linux/amd64"
  },
  "kustomizeVersion": "v4.5.7"
}

For Arch Linux users, you can also install this from AUR:

yay -Sy kubectl-bin
kubectl version

Step 5: Install Docker Machine KVM driver

The last item to install is the Docker machine driver for KVM. Download the binary and make it executable.

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/local/bin/

The package is available from AUR for Arch Linux users:

yay -Sy docker-machine-driver-kvm2

You can confirm version:

$ docker-machine-driver-kvm2 version
version: v1.28.0
commit: 986b1ebd987211ed16f8cc10aed7d2c42fc8392f

Step 6: Starting Minikube on KVM

With all components installed, you should be ready to start minikube with KVM driver.

Add your user account to libvirt group:

sudo usermod -aG libvirt $USER
newgrp libvirt

Set KVM as default driver:

minikube config set vm-driver kvm2

The minikube start command will download VM image and configure the Kubernetes single node cluster for you. Easy work!!..

$ minikube start
...................................
   minikube v1.28.0 on linux (amd64)
   Downloading Minikube ISO ...
129.33 MB / 129.33 MB [============================================] 100.00% 0s
   Creating kvm2 VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
   minikube v1.28.0 on linux (amd64)
   Configuring environment for Kubernetes v1.25.3
   Downloading kubeadm v1.25.3
   Downloading kubelet v1.25.3
   Pulling images ...
   Launching Kubernetes ... 
⌛  Verifying: apiserver proxy etcd scheduler controller dns
   Done! kubectl is now configured to use "minikube"

Wait for the download and setup to finish then confirm that everything is working fine. You should see a running VM with a domain named minikube.

$ sudo virsh list
 Id   Name       State
--------------------------
 1    minikube   running

Minikube Basic operations

Check cluster status:

$ kubectl cluster-info
Kubernetes master is running at https://192.168.39.188:8443
KubeDNS is running at https://192.168.39.188:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Minikube configuration file is located on:

~/.minikube/machines/minikube/config.json

To View Config, use:

$ kubectl config view
......................
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /root/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Mon, 23 Jan 2023 23:27:59 EAT
        provider: minikube.sigs.k8s.io
        version: v1.28.0
      name: cluster_info
    server: https://192.168.39.107:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Mon, 23 Jan 2023 23:27:59 EAT
        provider: minikube.sigs.k8s.io
        version: v1.28.0
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /root/.minikube/profiles/minikube/client.crt
    client-key: /root/.minikube/profiles/minikube/client.key

Check nodes:

$ kubectl get nodes
NAME       STATUS   ROLES           AGE    VERSION
minikube   Ready    control-plane   158m   v1.25.3

Access minikube VM using ssh:

$ minikube ssh
NAME       STATUS   ROLES           AGE    VERSION
minikube   Ready    control-plane   158m   v1.25.3
root@spinx01:~# minikube ssh
                         _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `| |/' _ `| || , <  ( ) ( )| '_`  /'__`
| ( ) ( ) || || ( ) || || |` | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`___/'(_,__/'`____)

$ cat /etc/os-release 
NAME=Buildroot
VERSION=2021.02.12-1-gb347f1c-dirty
ID=buildroot
VERSION_ID=2021.02.12
PRETTY_NAME="Buildroot 2021.02.12"

$ docker ps

To stop a running local kubernetes cluster, run:

$ minikube stop

To delete a local kubernetes cluster, use:

$ minikube delete

Step 7: Enable Kubernetes Dashboard

Kubernete ships with a web dashboard which allows you to manage your cluster without interacting with a command line. The dashboard addon is installed and enabled by default on minikube.

$ minikube addons list
...........................
|-----------------------------|----------|--------------|--------------------------------|
|         ADDON NAME          | PROFILE  |    STATUS    |           MAINTAINER           |
|-----------------------------|----------|--------------|--------------------------------|
| ambassador                  | minikube | disabled     | 3rd party (Ambassador)         |
| auto-pause                  | minikube | disabled     | Google                         |
| cloud-spanner               | minikube | disabled     | Google                         |
| csi-hostpath-driver         | minikube | disabled     | Kubernetes                     |
| dashboard                   | minikube | disabled     | Kubernetes                     |
| default-storageclass        | minikube | enabled ✅   | Kubernetes                     |
| efk                         | minikube | disabled     | 3rd party (Elastic)            |
| freshpod                    | minikube | disabled     | Google                         |
| gcp-auth                    | minikube | disabled     | Google                         |
| gvisor                      | minikube | disabled     | Google                         |
| headlamp                    | minikube | disabled     | 3rd party (kinvolk.io)         |
| helm-tiller                 | minikube | disabled     | 3rd party (Helm)               |
| inaccel                     | minikube | disabled     | 3rd party (InAccel             |
|                             |          |              | [info@inaccel.com])            |
| ingress                     | minikube | disabled     | Kubernetes                     |
| ingress-dns                 | minikube | disabled     | Google                         |
| istio                       | minikube | disabled     | 3rd party (Istio)              |
| istio-provisioner           | minikube | disabled     | 3rd party (Istio)              |
| kong                        | minikube | disabled     | 3rd party (Kong HQ)            |
| kubevirt                    | minikube | disabled     | 3rd party (KubeVirt)           |
| logviewer                   | minikube | disabled     | 3rd party (unknown)            |
| metallb                     | minikube | disabled     | 3rd party (MetalLB)            |
| metrics-server              | minikube | disabled     | Kubernetes                     |
| nvidia-driver-installer     | minikube | disabled     | Google                         |
| nvidia-gpu-device-plugin    | minikube | disabled     | 3rd party (Nvidia)             |
| olm                         | minikube | disabled     | 3rd party (Operator Framework) |
| pod-security-policy         | minikube | disabled     | 3rd party (unknown)            |
| portainer                   | minikube | disabled     | 3rd party (Portainer.io)       |
| registry                    | minikube | disabled     | Google                         |
| registry-aliases            | minikube | disabled     | 3rd party (unknown)            |
| registry-creds              | minikube | disabled     | 3rd party (UPMC Enterprises)   |
| storage-provisioner         | minikube | enabled ✅   | Google                         |
| storage-provisioner-gluster | minikube | disabled     | 3rd party (Gluster)            |
| volumesnapshots             | minikube | disabled     | Kubernetes                     |
|-----------------------------|----------|--------------|--------------------------------|

To open directly on your default browser, use:

$ minikube dashboard

To get the URL of the dashboard

$ minikube dashboard --url
http://192.168.39.117:30000

Open the link on the browser to access the Dashboard.

Cleaning up:

$ minikube delete --all --purge

The next thing to do is check getting started with Minikube guides like:

Storage Solutions:

17
1.215.830,30