Converged Platform for VM’s and Containers? Journey to KubeVirt!

Sakthi Saravanan
ITNEXT
Published in
5 min readJul 17, 2020

--

Before jumping into the details of KubeVirt, let’s understand the need for such tools. I would like to touch two such scenarios that would need KubeVirt.

Firstly, let’s take a case where you split the monolith architecture based project into microservices. In this case, as a practice, we would not split monolith into microservices at one go! We would gradually reach by doing a few services per iteration. So, you get two variants of deployable images that need two different platforms. i.e. To run the existing monolith based VM’s into some kind of virtualization management environments. Then you need container orchestrator tools like Kubernetes to deploy your extracted services of your Microservices.

Secondly, let’s take a case where containerization is not possible in the near future for your project functionality, e.g. some virtual network functions (VNF) like a load balancer, gateway but we plan to build some containers to manage or orchestrate the VNF that we would need. Here too, we would need two platforms to deploy the projects.

In both of these scenarios, the common problem would have cost, and skill set. You would need to spend money on two different platforms (if you choose to go with enterprise editions of vSphere and Kubernetes probably). Then you would need specialized resources in both of these platforms. In some cases, the team would find it difficult to adopt two different platforms and cause some flexibility issues. What if we could deploy and manage VMs into Kubernetes? Sounds great, right! That gives valuable time to concentrate on project functionalities, rather than spending time on understanding the platform where it runs. To address these needs, KubeVirt comes as a rescuer.

“KubeVirt is the open-source project that makes it possible to run virtual machines in a Kubernetes managed container platform. KubeVirt delivers container-native virtualization by leveraging KVM, the Linux Kernel hypervisor, within a Kubernetes container.” — from RedHat.

Converged Platform: Containers + VMs

Let’s walk through the process of spinning up a VM inside a Kubernetes platform. I assume that you have already deployed Kubernetes in your environment. To deploy VMs into the Kubernetes, you would need the KubeVirt specific pods installed on your Kubernetes platform. Such as,

  • KubeVirt Operator related pods
  • KubeVirt Custom Resources (CRD’s)
  • CDI Operator [this is used to upload VM image into your Kubernetes persistent volumes]
  • CDI Custom Resources (CRD’s) [instead of CDI you can upload directly using ‘virtctl’ command]

To install these pods, follow the below steps:

kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/v0.26.0/kubevirt-operator.yamlkubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/v0.26.0/kubevirt-cr.yamlkubectl apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/v1.18.2/cdi-operator.yamlkubectl apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/v1.18.2/cdi-cr.yaml

Verify all pods are installed properly by running below command and should give output as shown in the pic.

kubectl get pods -n kubevirt
KubeVirt related pods in the ‘kubevirt’ namespace
kubectl get pods -n cdi
CDI related pods in the ‘cdi’ namespace

Now, KubeVirt is up; to take our VM loads into the Kubernetes platform. To do this, we would need some more configurations from the Kubernetes side. Like, storage class, persistent volumes. We know that VMs need a disk to boot up. The Kubernetes' persistent volume would act like a disk for the VM. To set up this storage configuration locally, run the below YAML files in your Kubernetes platform. use ‘ kubectl create -f <file-name-of-below-contents>

To provision Storage Class:

Verify by running: ‘ kubectl get sc ’

To provision Persistent Volume:

Verify by running ‘ kubectl get pv ‘

Now, we would need to claim persistent volume for VMs that would be used as a disk. To claim persistent volume, run the following, this would import the image from the file host to the Kubernetes volumes using CDI. Source Image path would be specified in cdi.kubevirt.io/storage.import.endpoint field.

Once the image is imported, we would need to deploy our VM, right? To do that, KubeVirt exposes kind: VirtualMachineInstance. Install the VM using the below content. In our case, it would be the ubuntu image.

Once done, you can verify the status of running VM using the command:

kubectl get vmi

And you can connect to the VM console using:

virtctl console ubuntu-vm

Note: to install virtctl, please download the plugin from https://github.com/kubevirt/kubevirt/releases

There we are! We have managed to run VM’s on to our Kubernetes platform, now we can deploy container pods into the same platform as we would do usually. Hope this article serves as a better start to your journey towards KubeVirt.

Thanks, Manu Mathews for all the motivation! :)

--

--