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:
Deploy Production Kubernetes Cluster with Ansible & Kubespray
How To run Local Kubernetes clusters in Docker
Deploy Lightweight Kubernetes with MicroK8s and Snap
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:
Install KVM on CentOS 7 / Ubuntu / Debian / SLES / Arch Linux
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:
How to install Docker CE on Ubuntu / Debian / Fedora / Arch / CentOS
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.19.0 commit: 15cede53bdc5fe242228853e737333b09d4336b5
For Arch Linux users, you can install minikube from AUR:
$ yaourt -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": "21", "gitVersion": "v1.21.0", "gitCommit": "cb303e613a121a29364f75cc67d3d580833a7479", "gitTreeState": "clean", "buildDate": "2021-04-08T16:31:21Z", "goVersion": "go1.16.1", "compiler": "gc", "platform": "linux/amd64"
For Arch Linux users, you can also install this from AUR:
$ yaourt -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:
yaourt -Sy docker-machine-driver-kvm2
You can confirm version:
$ docker-machine-driver-kvm2 version
version: v1.19.0
commit: 15cede53bdc5fe242228853e737333b09d4336b5
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.19.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.19.0 on linux (amd64)
🐳 Configuring environment for Kubernetes v1.20.2
💾 Downloading kubeadm v1.20.2
💾 Downloading kubelet v1.20.2
🚜 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-data: DATA+OMITTED
server: https://192.168.42.106:8443
name: 192-168-42-106:8443
- cluster:
certificate-authority: /home/jmutai/.minikube/ca.crt
server: https://192.168.39.188:8443
name: minikube
contexts:
- context:
cluster: minikube
user: minikube
name: minikube
- context:
cluster: 192-168-42-106:8443
namespace: myproject
user: developer/192-168-42-106:8443
name: minishift
- context:
cluster: 192-168-42-106:8443
namespace: myproject
user: developer/192-168-42-106:8443
name: myproject/192-168-42-106:8443/developer
- context:
cluster: 192-168-42-106:8443
namespace: myproject
user: system:admin/192-168-42-106:8443
name: myproject/192-168-42-106:8443/system:admin
current-context: minikube
kind: Config
preferences:
users:
- name: developer/192-168-42-106:8443
user:
token: QdSKNK5DbaLA2AOFM__8-_fJ-Pt7BikZP1uFwsqyNx0
- name: minikube
user:
client-certificate: /home/jmutai/.minikube/client.crt
client-key: /home/jmutai/.minikube/client.key
- name: system:admin/192-168-42-106:8443
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
Check nodes:
$ kubectl get nodes NAME STATUS ROLES AGE VERSION minikube Ready master 35m v1.15.0
Access minikube VM using ssh:
$ minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ cat /etc/os-release
NAME=Buildroot
VERSION=2018.05.3
ID=buildroot
VERSION_ID=2018.05.3
PRETTY_NAME="Buildroot 2018.05.3"
$ 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-manager: enabled
- dashboard: disabled
- default-storageclass: enabled
- efk: disabled
- freshpod: disabled
- gvisor: disabled
- heapster: disabled
- ingress: disabled
- logviewer: disabled
- metrics-server: disabled
- nvidia-driver-installer: disabled
- nvidia-gpu-device-plugin: disabled
- registry: disabled
- registry-creds: disabled
- storage-provisioner: enabled
- storage-provisioner-gluster: disabled
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