KubeVirt technology enables you to manage virtual machines on Kubernetes. This solution addresses the need of running some bits of application that cannot be easily containerized in Virtual Machine on top of Kubernetes Cluster. This is helpful to Developers who have adopted or want to adopt Kubernetes but still have components of the application dependent on Virtual Machine. Teams with a reliance on existing virtual machine-based workloads are empowered to rapidly containerize applications.

With virtualized workloads placed directly in development workflows, teams can decompose them over time while still leveraging remaining virtualized components as is comfortably desired. KubeVirt gives you a unified development platform where you can build, modify, and deploy applications residing in both Application Containers as well as Virtual Machines in a common, shared environment.

As of today KubeVirt can be used to declaratively:

  • Create a predefined VM
  • Schedule a VM on a Kubernetes cluster
  • Launch a VM
  • Stop a VM
  • Delete a VM

In this tutorial we discuss the installation and use of KubeVirt on Minikube environment. Minikube is local Kubernetes which makes it easy to learn and develop for Kubernetes in your local machine – Personal Laptop or Home Desktop. KubeVirt is a We are a Cloud Native Computing Foundation sandbox project.

Step 1: Install Minikube

Start with the installation of Minikube using the commands below.


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


brew install minikube


#Using winget
$ winget install minikube

# Using Chocolatey
$ choco install minikube

Check version of Minikube to confirm it is installed properly and working:

$ minikube version
minikube version: v1.19.0
commit: 15cede53bdc5fe242228853e737333b09d4336b5

The version output may vary depending on the time you’re running the commands.

Refer to the official minikube guide for the installation on other systems.

Step 2: Install kubectl

Download kubectl command line tool to your system:

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

Make the kubectl binary executable.

chmod +x ./kubectl

Move the binary in to your PATH:

sudo mv ./kubectl /usr/local/bin/kubectl

Check 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"

Step 3: Install Virtualization Platform of choice

Depending on your system there are multiple options. The commonly used hypervisor is VirtualBox.

Install VirtualBox on Debian

Install VirtualBox on Ubuntu / Debian

Install VirtualBox on Fedora

Install VirtualBox on CentOS / RHEL 8

For KVM check below:

How To run Minikube on KVM

With everything set start Minikube instance:

$ minikube start

If minikube fails to start, see the drivers page for help setting up a compatible container or virtual-machine manager.

Example output for macOS:

😄  minikube v1.19.0 on Darwin 11.2.3
✨  Automatically selected the hyperkit driver. Other choices: vmware, parallels, virtualbox, ssh
💾  Downloading driver docker-machine-driver-hyperkit:
    > docker-machine-driver-hyper...: 65 B / 65 B [----------] 100.00% ? p/s 0s
    > docker-machine-driver-hyper...: 10.52 MiB / 10.52 MiB  100.00% 4.31 MiB p
🔑  The 'hyperkit' driver requires elevated permissions. The following commands will be executed:

    $ sudo chown root:wheel /Users/jkmutai/.minikube/bin/docker-machine-driver-hyperkit
    $ sudo chmod u+s /Users/jkmutai/.minikube/bin/docker-machine-driver-hyperkit

💿  Downloading VM boot image ...
    > minikube-v1.19.0.iso.sha256: 65 B / 65 B [-------------] 100.00% ? p/s 0s
    > minikube-v1.19.0.iso: 244.49 MiB / 244.49 MiB  100.00% 4.92 MiB p/s 49.90
👍  Starting control plane node minikube in cluster minikube
💾  Downloading Kubernetes v1.20.2 preload ...
    > preloaded-images-k8s-v10-v1...: 491.71 MiB / 491.71 MiB  100.00% 4.86 MiB
🔥  Creating hyperkit VM (CPUs=2, Memory=4000MB, Disk=20000MB) ...
🐳  Preparing Kubernetes v1.20.2 on Docker 20.10.4 ...
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: default-storageclass, storage-provisioner
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Step 4: Deploy KubeVirt

KubeVirt can be installed using the KubeVirt operator, which manages the lifecycle of all the KubeVirt core components. The easiest installation method is from minikube addon:

$ minikube addons enable kubevirt
    ▪ Using image bitnami/kubectl:1.17
🌟  The 'kubevirt' addon is enabled

 Check logs of the kubevirt-install-manager pod:

$ kubectl logs pod/kubevirt-install-manager -n kube-system
namespace/kubevirt created
customresourcedefinition.apiextensions.k8s.io/kubevirts.kubevirt.io created
priorityclass.scheduling.k8s.io/kubevirt-cluster-critical created
clusterrole.rbac.authorization.k8s.io/kubevirt.io:operator created
serviceaccount/kubevirt-operator created
role.rbac.authorization.k8s.io/kubevirt-operator created
rolebinding.rbac.authorization.k8s.io/kubevirt-operator-rolebinding created
clusterrole.rbac.authorization.k8s.io/kubevirt-operator created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt-operator created
deployment.apps/virt-operator created
use emulation
configmap/kubevirt-config created
kubevirt.kubevirt.io/kubevirt created

Check deployment status:

$ kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.phase}"

By default KubeVirt will deploy 7 pods, 3 services, 1 daemonset, 3 deployment apps, 3 replica sets.

$ kubectl get all -n kubevirt

See below screenshot with actual command output.

Deploy and Use KubeVirt on Minikube 01

Install KubeVirt which provides an additional binary called virtctl for quick access to the serial and graphical ports of a VM and also handle start/stop operations.

VERSION=$(kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.observedKubeVirtVersion}")
ARCH=$(uname -s | tr A-Z a-z)-$(uname -m | sed 's/x86_64/amd64/') || windows-amd64.exe
echo ${ARCH}
curl -L -o virtctl https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-${ARCH}
chmod +x virtctl
sudo install virtctl /usr/local/bin

Validate installation:

$ virtctl version
Client Version: version.Info{GitVersion:"v0.40.0", GitCommit:"127736619519e6b914e75930fc467c672e766e42", GitTreeState:"clean", BuildDate:"2021-04-20T08:34:39Z", GoVersion:"go1.13.14", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{GitVersion:"v0.40.0-dirty", GitCommit:"127736619519e6b914e75930fc467c672e766e42", GitTreeState:"dirty", BuildDate:"2021-04-20T08:57:15Z", GoVersion:"go1.13.14", Compiler:"gc", Platform:"linux/amd64"}

Step 5: Using KubeVirt

Now that you’ve installed KubeVirt in your Kubernetes Cluster powered by Minikube you can work through the labs to help you get acquainted with KubeVirt and how it can be used to create and deploy VMs with Kubernetes.

Deploy test VM instance.

wget https://raw.githubusercontent.com/kubevirt/kubevirt.github.io/master/labs/manifests/vm.yaml

Apply manifest file

$ kubectl apply -f vm.yaml
virtualmachine.kubevirt.io/testvm created

Run the command below to get a list of existing Virtual Machines and Status:

$ kubectl get vms
testvm   76s

Output in YAML format:

$ kubectl get vms -o yaml testvm

To start a Virtual Machine you can use:

$ virtctl start testvm
VM testvm was scheduled to start

Check the Virtual Machine status:

$ kubectl get vmis

NAME     AGE     PHASE     IP            NODENAME
testvm   2m20s   Running   minikube

$ kubectl get vmis -o yaml testvm

Connect to the serial console of the Cirros VM. Hit return / enter a few times and login with the displayed username and password.

$ Virtctl console testvm
Successfully connected to testvm console. The escape sequence is ^]

login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
testvm login:

Disconnect from the virtual machine console by typing: ctrl+].

Shutting down the VM:

$ virtctl stop testvm
VM testvm was scheduled to stop

Delete the Virtual Machine:

$ kubectl delete vm testvm
virtualmachine.kubevirt.io "testvm" deleted

Further readings:

More guides on containers:

How to change pids_limit value in OpenShift 4.x

How To Setup your Heroku PaaS using CapRover

How To Create LXC Containers using Terraform

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here