KubeVirt on OpenShift
UPDATED: 17 May 2019
A quick HowTo get KubeVirt running on OpenShift.
Requirements
A few requirements need to be met before you can begin:
- OpenShift/Kubernetes cluster
oc
client utilitygit
Minimum Cluster Requirements
Openshift 3.10 or later is required to run KubeVirt.
Virtualization support
Hardware with virtualization support is recommended. You can use virt-host-validate
to ensure that your hosts are capable of running virtualization workloads:
$ virt-host-validate qemu
QEMU: Checking for hardware virtualization : PASS
QEMU: Checking if device /dev/kvm exists : PASS
QEMU: Checking if device /dev/kvm is accessible : PASS
QEMU: Checking if device /dev/vhost-net exists : PASS
QEMU: Checking if device /dev/net/tun exists : PASS
...
Or you can check using egrep 'svm|vmx' /proc/cpuinfo
If the command doesn’t generate any output, then use the software emulation below.
Software emulation
If hardware virtualization is not available, then a software emulation fallback can be enabled using:
$ oc new-project kubevirt
$ oc create configmap -n kubevirt kubevirt-config --from-literal debug.useEmulation=true
This ConfigMap needs to be created before deployment or the virt-controller
deployment has to be restarted.
Deploying on OpenShift
Core components
The installation uses the KubeVirt operator, which manages lifecycle of all KubeVirt core components:
# Create the kubevirt project/namespace
$ oc new-project kubevirt
# Check if your Server/VM’s CPU supports virtualization extensions
$ egrep 'svm|vmx' /proc/cpuinfo
# If the command doesn’t generate any output, create the following ConfigMap so that KubeVirt uses emulation mode, otherwise skip to the next section:
$ oc create configmap -n kubevirt kubevirt-config --from-literal debug.useEmulation=true
# Deploy KubeVirt
# The following SCC needs to be added prior KubeVirt deployment
$ oc adm policy add-scc-to-user privileged -n kubevirt -z kubevirt-operator
# Set the version
$ export RELEASE=v0.17.0
# creates KubeVirt operator
$ oc apply -f https://github.com/kubevirt/kubevirt/releases/download/${RELEASE}/kubevirt-operator.yaml
# creates KubeVirt KV custom resource
$ oc apply -f https://github.com/kubevirt/kubevirt/releases/download/${RELEASE}/kubevirt-cr.yaml
# wait until all KubeVirt components is up
$ oc -n kubevirt wait kv kubevirt --for condition=Ready
# On the client side, install virtctl
$ curl -L -o /usr/local/bin/virtctl https://github.com/kubevirt/kubevirt/releases/download/${RELEASE}/virtctl-${RELEASE}-linux-amd64
$ chmod +x /usr/local/bin/virtctl
# ref:
# https://kubevirt.io/user-guide/docs/latest/administration/intro.html
Installing Web User Interface (optional)
When the KubeVirt is installed on OpenShift, the Web User Interface can be used to administer the virtual machines and other entities in the cluster in addition to the command line tools.
$ git clone https://github.com/kubevirt/web-ui-operator.git
$ cd web-ui-operator/deploy
$ oc new-project kubevirt-web-ui
$ oc apply -f service_account.yaml
$ oc apply -f role.yaml
$ oc apply -f role_binding.yaml
$ oc apply -f crds/kubevirt_v1alpha1_kwebui_crd.yaml
$ oc apply -f operator.yaml
# update version in crds/kubevirt_v1alpha1_kwebui_cr.yaml to the version you want (see https://quay.io/repository/kubevirt/kubevirt-web-ui?tab=tags)
$ oc apply -f crds/kubevirt_v1alpha1_kwebui_cr.yaml
# ref:
# 1. https://github.com/kubevirt/web-ui-operator
# 2. Kubevirt Web UI Operator: https://www.youtube.com/watch?v=99TvYSwJw5s
# 3. KubeVirt Web User Interface: https://www.youtube.com/watch?v=ouqiFeQN6cs
Installing Containerized Data Importer (optional)
Containerized Data Importer (CDI) is a utility to import, upload and clone Virtual Machine images for use with Kubevirt. At a high level, a persistent volume claim (PVC), which defines VM-suitable storage via a storage class, is created.
Deploying the CDI controller is straightforward.
$ export VERSION=$(curl -s https://github.com/kubevirt/containerized-data-importer/releases/latest | grep -o "v[0-9]\.[0-9]*\.[0-9]*")
$ oc apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-operator.yaml
$ oc apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-operator-cr.yaml
# ref:
# https://github.com/kubevirt/containerized-data-importer
Deploy a VirtualMachine
Now that KubeVirt is ready, let’s deploy our first VM:
oc apply -f https://raw.githubusercontent.com/kubevirt/kubevirt.github.io/master/labs/manifests/vm.yaml
Using oc we can get the object and its YAML definition:
oc get vms
oc get vms -o yaml testvm
Note the field running is set to false, that means we’ve only defined the object but it now needs to be instantiated. So let’s start the VM:
virtctl start testvm
Then again, using oc, let’s query for the VM instance:
oc get vmis
oc get vmis -o yaml testvm
Note the added i, as it stands for VirtualMachineInstance. Now, pay attention to the phase field, its value will be transitioning from one state to the next, indicating VMI progress to finish being set to Running.
Using again virtctl, let’s connect to the VMI consoles interfaces:
virtctl console testvm
virtctl vnc testvm
Remember that for exiting from the console to hit Ctrl+] (Control plus closing square bracket).
Note: VNC requires remote-viewer from the virt-viewer package installed on the host.
Clean Up:
Let’s stop the VM instance:
virtctl stop testvm
Delete the VM:
oc delete vm testvm
Ref: