Deploying KubeVirt On Kubernetes

kubevirt kubernetes
kubevirt kubernetes

Deploy KubeVirt Operator

An Operator is a method of packaging, deploying, and managing a Kubernetes application. A Kubernetes application is one that is deployed on Kubernetes and managed using the Kubernetes APIs and kubectl tooling. You can think of Operators as the runtime that manages this type of application on Kubernetes. If you want to learn more about Operators you can check the Kubernetes documentation

Here, we query GitHub’s API to get the latest available release: (click on the text to automatically execute the commands on the console):

export KUBEVIRT_VERSION=$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | jq -r .tag_name)
echo $KUBEVIRT_VERSION

Run the following command to deploy the KubeVirt Operator:

kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml

Now deploy KubeVirt by creating a Custom Resource that will trigger the ‘operator’ reaction and perform the deployment:

kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml

Next, we need to configure KubeVirt to use software emulation for virtualization. This is necessary for the course environment but results in poor performance so avoid this step in production environments.

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

Install Virtctl

While we are waiting for the KubeVirt operator to start up all its Pods, we can take some time to download the client we will need to use in the next step.

virtctl is a client utility that helps interact with VM’s (start/stop/console, etc):

wget -O virtctl https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64
chmod +x virtctl

Wait for KubeVirt deployment to finalize

Let’s check the deployment:

kubectl get pods -n kubevirt

Once it’s ready, it will show something similar to:

controlplane $ kubectl get pods -n kubevirt
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

As there are multiple deployments involved, the best way to determine whether the operator is fully installed is to check the operator’s Custom Resource itself:

kubectl -n kubevirt get kubevirt

Once fully deployed, this will look like:

NAME      AGE   PHASE
kubevirt  3m    Deployed

Now everything is ready to continue and launch a VM.

Deploy a Virtual Machine

The command below applies a YAML definition of a virtual machine into the current Kubernetes environment, defining the VM name, the resources required (disk, CPU, memory), etc. You can take a look at the vm.yaml file if you have interest in knowing more about a virtual machine definition:

kubectl apply -f https://kubevirt.io/labs/manifests/vm.yaml

We are creating a Virtual Machine in the same way as we would create any other Kubernetes resource thanks to the KubeVirt operator in our environment. Now we have a Virtual Machine as a Kubernetes resource.

After the vm resource has been created, you can manage the VMs with standard ‘kubectl’ commands:

kubectl get vms
kubectl get vms -o yaml testvm | grep -E 'running:.*|$'

Notice from the output that the VM is not running yet.

To start a VM, use virtctl with the start verb:

./virtctl start testvm

Again, check the VM status:

kubectl get vms

VirtualMachine resource contains a VM’s definition and status. An instance of a running VM has an additional associated resource, a VirtualMachineInstance.

Once the VM is running you can inspect its status:

kubectl get vmis

Once it is ready, the command above will print something like:

NAME      AGE       PHASE     IP           NODENAME
testvm    1m        Running   10.32.0.11   controlplane

Access a VM (serial console & vnc)

Now that the VM is running you can access its serial console:

./virtctl console testvm

In environments where VNC client access is available, the graphical console of a VM can be accessed with the virtctl vnc command.

Shutdown and cleanup

As with starting, stopping a VM also may be accomplished with the virtctl command:

./virtctl stop testvm

Finally, the VM can be deleted as any other Kubernetes resource using kubectl:

kubectl delete vms testvm

Author

  • Mohamed BEN HASSINE

    Mohamed BEN HASSINE is a Hands-On Cloud Solution Architect based out of France. he has been working on Java, Web , API and Cloud technologies for over 12 years and still going strong for learning new things. Actually , he plays the role of Cloud / Application Architect in Paris ,while he is designing cloud native solutions and APIs ( REST , gRPC). using cutting edge technologies ( GCP / Kubernetes / APIGEE / Java / Python )

    View all posts
0 Shares:
Leave a Reply
You May Also Like
What is Cilium CNI
Read More

What is Cilium CNI

Table of Contents Hide What is Cilium Cilium Installation PrerequisitesCreating a Kubernetes ClusterInstallationCilium CLIHubble – observability according to…