logo

Kubernetes - KubeVirt

Last Updated: 2023-08-19

KubeVirt: manage VMs in k8s. KubeVirt enables KVM-based virtual machine workloads to be managed as pods in Kubernetes.

KubeVirt reached 1.0 in 2023. https://kubevirt.io/

Note: pod != container; a pod can have one or multiple containers and/or VMs.

Why KubeVirt?

  • For teams that want to adopt k8s but have legacy VM based workloads.
  • Cost savings, from eliminating hypervisor license and efficient resource utilization across containers and VMs.

What does KubeVirt offer:

  • auto provision new volume via k8s CSI.
  • Containerized Data Importer (CDI) copies data to boot disk from source (supported sources: HTTP endpoint, container registry, clone from another PVC, upload from a client, etc).

Components

  • Control plane: virt-controller, virt-api.
  • Worker node: virt-handler, a DaemonSet.
  • Per VMI: qemu->libvirtd->virt-launcher.
  • CLI: virtctl.

How does KubeVirt work?

The kernel-based virtual machine (KVM) hypervisor is itself a Linux process that can be containerized.

  • KubeVirt uses QEMU; QEMU is the actual process to give you a VM.
  • KubeVirt launches QEMU in a container using virt-launcher.
  • One pod per VMI (virtual machine instance).
  • virt-controller -> API server -> DeamonSet virt-handler -> virt-launcher.
  • How to keep vm alive if they are on pod? Live migration to other pod.

Where

kubevirt can run on bare metal cluster, or on public cloud instances (VMs on VMs, negative performance impact).

User Interfaces

No UI, only CLI or API.

VM vs Pod

  • VM needs a static ip address and a mac address; needs L2 connectivity to external network.
  • kubevirt deploys VM inside a pod; VM uses a macvtap interface to get direct connection to the physical network, and get static mac address and static ip address.

Extra

  • Snapshot Controller to provide snapshot capabilities to the VMs and referenced volumes
  • Containerized Data Importer (CDI) to facilitate enabling persistent volume claims (PVCs) to be used as disks for VMs (as DataVolumes).
  • Multus to provide virtual local area network (VLAN) network access to virtual machines

APIs

  • VirtualMachine: The VirtualMachine contains the template to create the VirtualMachineInstance.
  • VirtualMachineInstance
  • DataVolume: monitor and orchestrate the import/upload/clone of the data into the PVC.

Containerized-Data-Importer (CDI)

Containerized-Data-Importer (CDI) is a persistent storage management add-on for Kubernetes. It's primary goal is to provide a declarative way to build Virtual Machine Disks on PVCs for Kubevirt VM.

CDI provides the ability to populate PVCs with VM images or other data upon creation.

CLI

Install KubeVirt virtctl via Krew:

$ kubectl krew install virt