Getting Started with KubeVirt Containers and Virtual Machines Together

Virtual machines have existed for a long time and have filled a critical role providing infrastructure on demand to application administrators and developer teams who need to be able to code, test and deploy faster than can be done with physical infrastructure. However, container technology–which isn’t new but has seen a rise in popularity in recent years–is poised to supplant virtualization as the preferred application deployment mechanism for many use cases.

Containers decouple the application from the operating system in the same way that virtualization decoupled the operating system from the hardware. They can allow for simplified separation of responsibilities between developers and system administrators, enabling each to focus on the components of the stack which they care most about. Container platforms, such as Red Hat’s OpenShift–an enterprise version of the popular Kubernetes platform–are designed to provide a suite of capabilities beyond simple application abstraction and deployment. A container orchestration platform enables the application team to define how the components of a cloud native application should be deployed, connected and scaled without having to worry about the details. Application deployments using containers, and container orchestrators, can reduce friction between the operations team and the application team by helping to remove requests for new and changed resources.

However, containers are not a perfect fit for all situations. Sometimes a virtual machine is needed by applications, or application components, to provide features such as kernel isolation, dedicated resources, or simply an environment which is supported by a third-party vendor. Maybe you’re ready to migrate your applications wholly to containers, but the applications still have components which must be virtualized? How do you get the benefits of a virtual machine and container together?

One answer: KubeVirt. KubeVirt is an open source project which enables virtual machines to be deployed, consumed, and managed by Kubernetes just like containers. Having a single deployment and management plane for both containers and virtual machines is designed to enable a unified platform for cloud-native applications, regardless of the requirements. For example, perhaps the application that you are developing is mostly composed of container-based microservices, but there’s that one nagging legacy service that can only run in a VM. With KubeVirt, you can have that VM run inside a container, managed by Kubernetes, along with the containers that host the other services/microservices.

From zero to VMs in three minutes

Getting started with KubeVirt can be simple, all you need is one of two things: a bare metal Kubernetes 1.10+ or OpenShift 3.10+ cluster. If you are wanting to just test functionality, you can also use emulation instead of virtualization for the virtual machines, just be aware of the performance impact.

We’ll be following the quick start guide from the documentation, be sure to read the full install documentation if you are curious about how to customize your deployment.

After identifying your cluster, deploy using the CLI:

# add permissions if using OpenShift
oc adm policy add-scc-to-user privileged -n kube-system -z kubevirt-privileged
oc adm policy add-scc-to-user privileged -n kube-system -z kubevirt-controller
oc adm policy add-scc-to-user privileged -n kube-system -z kubevirt-apiserver
# apply the KubeVirt configuration, adjust RELEASE for the current version
RELEASE=v0.11.0
kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/${RELEASE}/kubevirt.yaml


Ansible will deploy the components and example content, which you can explore using standard kubectl or oc commands. Before moving on, you’ll also want to deploy virtctl, the CLI tool for managing virtual machines, from GitHub.

To deploy a test virtual machine, a sample config file can be found in the kubevirt/demo project on GitHub. We can deploy with one command:

# use the oc command if deploying to OpenShift
kubectl create -f https://raw.githubusercontent.com/kubevirt/demo/master/manifests/vm.yaml

A newly created virtual machine starts in the powered off state, so to start it we will want to use virtctl. If you want to see the virtual machines in your cluster, use the command kubectl get vms.

# start the virtual machine
virtctl start testvm

The CirrOS based virtual machine image will be started on a node in the Kubernetes or OpenShift cluster. Viewing running virtual machines in the cluster can be done using the kubectl get vmi command, and you can connect to the console using the command virtctl console testvm, or if you have remote-viewer installed, connect via VNC using the command virtctl vnc testvm.

Containers AND virtual machines, not OR!

There are many ways to deploy applications and the best way is going to be different for every application. As an application team, choosing between virtualization and containerization often meant a trade off in convenience and speed to deploy, having to orchestrate across multiple platforms. KubeVirt combines both worlds, enabling Kubernetes to schedule, deploy, and manage virtual machines just like any other containerized workload.

If you believe that KubeVirt is a good fit for your application, please give it a try! Getting started is easy and we’ve only scratched the surface of the capabilities in this blog post. Subscribe to the mailing list, visit us on GitHub, check out our other blog post today, or contact us on Twitter for more information or help.

Categories
Containers, OpenShift Ecosystem
Tags
, ,