Guided Exercise: Installing KubeVirt

Set up your Kubernetes cluster

In order to install KubeVirt, you need to have a Kubernetes cluster you can access via kubectl commands, and be logged in as a user who can create namespaces and cluster resources, typically a cluster admin.

Minikube and Kind clusters are sufficient to try out basic KubeVirt functionality, but it is recommended to  install a container network interface (CNI) like flannel. See documentation for your preferred cluster installation to see how to do this.

Grab the latest version of KubeVirt

We start by picking up the latest version of KubeVirt and setting an environment variable KUBEVIRT_VERSION for later commands:

KUBEVIRT_VERSION=$(curl -s | awk -F '[ \t":]+' '/tag_name/ {print $3}')

The command above reads GitHub's list of KubeVirt releases in latest first order, filters out any non stable releases, and prints the version string at the top of the list. At the time of this writing, the latest KubeVirt release is "v0.59.0".

Next, we use kubectl to install the KUBEVIRT_VERSION release of the KubeVirt operator:

kubectl create -f${KUBEVIRT_VERSION}/kubevirt-operator.yaml

This command will create a namespace, "kubevirt" and install the Custom Resource Definitions for KubeVirt we described earlier, as well as an operator that will wait for a configuration resource to launch the KubeVirt installation.

Now we add the Kubevirt Custom Resource (called kubevirt) that will trigger the KubeVirt operator to install the rest of KubeVirt:

kubectl create -f${KUBEVIRT_VERSION}/kubevirt-cr.yaml

To nest or not to nest

In some test environments, such as when minikube needs to run in a VM on your workstation, you may not have direct access to your local virtualization hardware, and may need to enable emulation mode:

kubectl -n kubevirt patch kubevirt kubevirt --type=merge --patch '{"spec":{"configuration":{"developerConfiguration":{"useEmulation":true}}}}'

If in doubt, skip this for now. If VMs fail to schedule because no nodes were found with kvm, you can patch and try again.

Install the KubeVirt client, virtctl

Depending on whether the Kubernetes cluster you are running on is a test environment like Minikube, it may take several minutes to get everything up and running. While we wait for that, we can take the time to download the virtctl command line client for KubeVirt:

curl -Lo virtctl${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64

To make sure the downloaded binary is executable, run:

chmod +x virtctl

It is recommended to place the virtctl binary somewhere in your shell's PATH such as $HOME/.local/bin or /usr/local/bin

Note that these are instructions for downloading a Linux 64 bit Intel compatible binary, if your own platform differs, have a look at and scroll down. Currently, there are also versions for Apple MacOSX and Microsoft Windows.

Wait for KubeVirt to fully deploy

We can check the KubeVirt deployment in several different ways. To get the most concise yes or no answer, we check the phase of the Kubevirt CR itself:

kubectl -n kubevirt get kubevirt

Once KubeVirt fully deploys, it will show:

kubevirt  3m    Deployed

For a more detailed view of what is being installed, (and to help understand if there are problems with the installation) you can list the Pods running in the kubevirt Namespace:

kubectl get pods -n kubevirt

Once the deployment finishes, this should look similar to:

NAME                               READY     STATUS    RESTARTS   AGE
virt-api-7fc57db6dd-g4s4w          1/1       Running   0          3m
virt-api-7fc57db6dd-zd95q          1/1       Running   0          3m
virt-controller-6849d45bcc-88zd4   1/1       Running   0          3m
virt-controller-6849d45bcc-cmfzk   1/1       Running   0          3m
virt-handler-fvsqw                 1/1       Running   0          3m
virt-operator-5649f67475-gmphg     1/1       Running   0          4m
virt-operator-5649f67475-sw78k     1/1       Running   0          4m