KubeVirt: Part 1 - Theory and Prerequisites (deprecated)

In short
  • This article is outdated and has been replaced by the KubeVirt V2 series.
  • Add support for VMs to Kubernetes with KubeVirt.
  • Target architecture with multiple network cards/VLANs via Multus and macvtap.
  • Lesson: modularity and a lot of assembly of third-party components.

Introduction

This article is from an old tutorial. Its content may be outdated. I invite you to continue on the new version of the cookbook.

Kubernetes here, Kubernetes there... the platform for running and developing containerized applications continues to generate discussion and expand its ecosystem.

As adoption increases, new use cases emerge.

As early as 2017, RedHat wondered if it was possible to add support for VMs to K8S. This led to KubeVirt.

After a few years of development, it came under the management of the Cloud Native Computing Foundation (CNCF). The project is still in incubating status at the time of writing this article.

the KubeVirt project

Click the image to enlarge.

On the RedHat side, KubeVirt is integrated into the OpenShift suite, their commercial Kubernetes distribution (but not only). This allows them to have a platform capable of handling both containers and VMs through a single execution and interaction logic.

Benefits of KubeVirt

This is where the benefit of KubeVirt lies: leveraging the modular structure of Kubernetes and its object manipulation to offer universal management of containerized and virtualized workloads.

In theory, it's great. In practice, however, when you try to implement the various necessary components yourself, especially on "standard" hardware, it's a different story... even AI can give up (believe me, I pushed ChatGPT to its limits).

The problem is that we are still in a phase of significant development and adjustment, mainly around network components.

While KubeVirt itself relies on existing and well-established technologies, particularly KVM and Kubernetes itself, this is not necessarily the case for all of the drivers and applications needed to ensure the overall system's cohesion.

It's certainly easier when you purchase a commercial license for OpenShift and deploy the product on certified hardware than when you try to recreate the entire logic on equipment accessible to everyone.

However, that is what I have tried to do, and what I will attempt to detail through various dedicated articles.

But why?

Why? Because given the current atmosphere in the IT market and the distrust surrounding VMware since its acquisition by Broadcom, I think it's worthwhile to explore KubeVirt. This is without necessarily relying on complete solutions from industry giants, with the potential risk of changes to pricing… be aware, I am not falling into paranoia; using ready-made platforms remains a choice to consider and is strongly recommended for many organizations: it all depends on the context, constraints (financial/human/legal/security) and the company's strategy.

But in any case, knowing what lies beneath the engine is never useless!

Although the internet already contains numerous tutorials on KubeVirt, few go as far as providing a concrete implementation example.

In my case, the primary goal is to achieve a complete alternative to ESXi, including the ability to run multiple VMs in different network zones. All while retaining the original purpose of Kubernetes through the deployment of containerized applications, via segmentation compatible with security constraints, and with controlled management of deployed assets.

I will expand on these needs as I make discoveries and conduct experiments, with the ultimate goals of forming an idea about the ability of a Kubernetes/Kubevirt ecosystem to completely replace a VMware ecosystem (and especially how to implement it).

This is perfectly complementary to my trials of the XCP-ng/Xen Orchestra suite. At least, I will have some minimal experience with different ecosystems, so as not to be too lost in this IT market that is often disrupted… at least on the technical side… on the management/marketing side, it changes less… many leaders, few workers.

The Basics

So, we'll start with a bit of theory and review all the components that we will be using and manipulating.

I'm going to use the same base as I used in my article on integrating a GPU into a K8S platform for AI use cases.

Unlike my standard lab, which is based on a multi-node Kubernetes cluster and serves as a reference for my CookBook on K8S, I will initially be using a single physical server named prdk8sctp001 with the following characteristics:

  • OS: Rocky Linux 9.5
  • CPU: Ryzen AMD Ryzen 9 7900X (12 cores / 24 threads)
  • GPU: NVIDIA 3060 12GB vRAM
  • RAM: 96 GB
  • Storage: 2 NVME SSDs (1TB) + 2 SATA SSDs (2 TB)
  • Network:
    • An integrated RTL8125 2.5GbE card
    • A PCI-E NetXtreme BCM5719 Gigabit 4-port card

Be aware of network cards

I would like to draw your attention specifically to the network hardware configuration.

List of network cards on the server

Click the image to enlarge.

This is indeed a point to consider if you want to embark on this adventure yourself, whether for pleasure or in your work.

First, unlike my example, avoid using integrated cards such as Realtek. As you will see later, they are a pain to use in a somewhat professional environment. Secondly, if possible, choose chipsets that are compatible with the SR-IOV standard; this is often the case with dedicated Intel cards. I will talk about this further in the following sections, but when you don't have compatible hardware, it's already more complex, even though you eventually manage to make it work.

In my case, the cards are not… just to make the challenge a bit harder… so the tutorial presented will be based on the least favorable situation...

Kubernetes configuration

I won't go into great detail about installing Kubernetes. I describe this in my cookbook.

This is a "vanilla" installation using kubeadm, following this configuration file.

  
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
kubernetesVersion: 1.31.3
networking:
 podSubnet: "10.11.0.0/16"
 serviceSubnet: "10.12.0.0/16"
controlPlaneEndpoint: "rubikub.coolcorp.priv:6443"
clusterName: "rubikub"
controllerManager:
  extraArgs:
    cloud-provider: external
apiServer:
 certSANs:
 - 192.168.10.160
 - rubikub.coolcorp.priv
    

Feel free to browse this article if you want to know more.

In the end, I have a Kubernetes node running version v1.31.6.

Specifics of a single-node setup

Since I don't currently have time to add nodes to the cluster, I need to remove the execution restriction that is set by default on a control plane node.

In my case, my server will also act as a worker node. Therefore, I am obliged to remove the taint that was applied during the initialization of the cluster to allow components to be deployed on it.

kubectl taint node prdk8sctp001 node-role.kubernetes.io/control-plane:NoSchedule-
Removing the taint from the control plane

Click the image to enlarge.

Warning: I do not recommend performing this operation in a production environment. If you already have a complete cluster, it is unnecessary to run this command and reserve your control plane only for system components (and ensure you have at least three control planes).

At this stage, we have a simple physical node with a Linux operating system installed, in this case Rocky Linux 9.5, on which Kubernetes is running in version 1.31.6, currently without any CNI (Container Network Interface) drivers.

That's why the output of the kubectl get node command shows a node with the status "not ready".

Cluster status

Click the image to enlarge.

Container Network Interfaces (CNIs)

Before proceeding further, it is necessary that you have at least a basic understanding of what a CNI is. In this case, it is a network driver used by Kubernetes and based on a standard common to all K8S platforms.

Feel free to visit here for more information on this topic, especially regarding Cilium, as it will be the first CNI we deploy.

KubeVirt components

It is also important to define what we mean when we talk about KubeVirt.

A diagram is invaluable for understanding:

the KubeVirt project

Click the image to enlarge.

Virtualization layer

First, let's discuss the part dedicated to running VMs.

Application Role
KVM Type I hypervisor integrated into the Linux kernel and used to run VMs
QEMU Provides emulation and device management for VMs
libvirt VM management API used by KubeVirt
KubeVirt Integrates VM management into Kubernetes and orchestrates their execution via KVM

Kubernetes components

If we focus more on the Kubernetes side, specifically regarding networking:

Technology Main Role Usage with KubeVirt
Cilium Pod/VM network connectivity Provides the primary network connectivity for VMs
Multus Adds multiple network interfaces to a K8S object Allows adding additional network interfaces to VMs
macvtap Direct L2 connection Attaches a physical interface to the VM

Operation

To function, Kubvirt will require the deployment of Custom Resource Definitions (CRDs) to extend the Kubernetes API with these objects:

  • VirtualMachineInstance (VMI): A running virtual machine instance.
  • VirtualMachine (VM): A persistent VM that can be stopped and restarted.
  • VirtualMachineReplicaSet: Similar to Kubernetes ReplicaSets, allowing management of multiple VM instances.
  • VirtualMachineInstancePreset: Template for standardizing VM configurations.

Other objects dedicated to Multus will be deployed, specifically the NetworkAttachmentDefinition, but we will discuss them later.

Deploying Kubevirt involves deploying all the necessary dependencies for processing VMs. Since these are Kubernetes (K8S) objects, they can leverage a wide range of other native Kubernetes objects to function, such as PersistentVolume (PVs) for storage.

To cover the virtualization aspect, instead of relying on a container runtime compatible with the CRI (Container Runtime Interface) standard, as Kubernetes does natively, Kubevirt will rely on KVM, the leading hypervisor under Linux. This is used by many solutions, such as ProxMox, for example. It is a type 1 hypervisor (feel free to take a look here) that is widely deployed, including in cloud infrastructures like those of GCP or AWS.

The QEMU component is also well-known among Linux users and will be used to provision the virtual devices that can be declared within the VMs.

Kubevirt relies on both the Kubernetes API for communicating with the cluster and the API provided by libvirt for managing KVM.

Regarding networking, it is initially possible to use only the CNI that you have decided to deploy with your K8S cluster, for example, as in my cookbook with Cilium.

However, for VM usage, this may not be sufficient. Indeed, we may need to deploy virtual machines equipped with multiple network interfaces, which is not possible by default with K8S.

To address this, we will use a meta CNI driver, Multus. This will interface with Cilium and allow K8S objects, such as pods, and by extension the new VM objects, to use more than one network interface if necessary.

Finally, to reproduce a situation closer to reality where we often find multiple physical network cards on a hypervisor dedicated to specific interconnections, we will use macvtap.

It is at this level that we note the greatest instability due to the still "alpha" nature of using macvtap with Kubevirt. This CNI allows a physical card to be subdivided into multiple virtual interfaces, which can then be used by Multus to provide the interfaces visible in the VMs.

By combining all these layers, we can manage multiple virtual machines, each mapped to specific networks, or even multiple specific networks. This results in a more traditional operating scheme, especially when compared to VMware.

Be aware that the mactap driver has been around for a long time, but its use as a CNI is still relatively recent and not always stable, particularly on somewhat "exotic" network cards like my little Realtek card. That's why I advised you at the beginning of this article to have SR-IOV compatible chipsets, which should (at least in theory; I haven't tested it) allow you to avoid the instability of the mactap driver mapping within a VM provisioned by KubeVirt.

Defining the target architecture

It is all these components that will be used to achieve the demonstration shown in the following illustration:

Interconnection diagram for the tutorial

Click the image to enlarge.

The idea is to ultimately offer three VMs.

  • One mapped to my LAN: it will use the physical Realtek interface enp8s0
  • One mapped to my WEB VLAN: it will use the physical Realtek interface enp8s0, but with tag 6 to generate a VLAN interface enp8s0.6
  • One mapped to my DMZ: it will use the physical interface connected to port 3 of my Broadcom card, which is the interface enp13s0f3

Note that I am using port 0 (enp13s0f0) of my Broadcom card, which is also on the LAN and used as an administration port, dedicated to accessing the prdk8sctp001 server itself and the Kubernetes API.

Of course, the network devices upstream of the server must be configured correctly. This is the case here on port 7 of my switch (Netgear), which is connected to my enp8s0 interface: the switch port is tagged with VLAN6 and untagged on VLAN 1

Switch configuration: VLAN6 tag

Click the image to enlarge.

Switch configuration: untagged on the default VLAN 1

Click the image to enlarge.

We will thus have a complete illustration based on my original lab and the network zones used in the context of hosting VMs under VMware and XCP-NG.

Now that the theory has been explained, let's move on to the first steps.

Setting up prerequisites

Changing the default Realtek drivers

The first task is to try to mitigate potential issues with my Realtek card. This part is optional if you don't have a card of this type. But I had so many problems that I thought it might be useful to some people.

In the diagram I presented earlier, this card must provide both the LAN and the WEB VLAN to my VMs under KubeVirt.

By default, it uses an old driver called R8169, which can be identified with the following command:

ethtool -i enp8s0
Identifying the Realtek network driver

Click the image to enlarge.

It is clearly unsuitable for my use case, and we will need to rely on the r8125 driver

To do this, we start by removing the R8169 driver module (as root):

rmmod r8169
Removing the module

Click the image to enlarge.

Then, we install a supplementary repository, elrepo:

dnf install -y elrepo-release
Installing the additional repository

Click the image to enlarge.

This will allow us to access and install the r8125 driver:

dnf install -y kmod-r8125
Installing the new driver

Click the image to enlarge.

We load the associated module:

modprobe r8125
Adding the module

Click the image to enlarge.

Normally, if we re-run ethtool -i enp8s0, we should see confirmation that the new driver is loaded.

Checking the driver

Click the image to enlarge.

We need to make this persistent, so we create a blacklist file to prevent the r8169 module from loading:

echo "blacklist r8169" | sudo tee /etc/modprobe.d/blacklist-r8169.conf dracut -f

We ensure that the r8125 module is loaded at startup:

echo "r8125" | sudo tee /etc/modules-load.d/r8125.conf dracut -f
Setting up persistent configuration

Click the image to enlarge.

Then, we reboot to be sure of the configuration.

A quick check using the ethtool -i enp8s0 command should reassure us.

Network profile definitions

To make things easier for the next steps, it is recommended to organize your network interfaces in a way that aligns with the target you want to achieve.

We can use the nmtui tool for this purpose.

This allows us to graphically name our interfaces and apply a basic configuration.

In this case, we will create:

  • a data-network configuration attached to my enp8s0 interface
  • a dmz-network configuration attached to my enp13s0f3 interface
  • a console-network configuration for my enp13s0f0 interface
Using nmtui

Click the image to enlarge.

Using nmtui: console-network profile

Click the image to enlarge.

Using nmtui: data-network profile

Click the image to enlarge.

Using nmtui: dmz-network profile

Click the image to enlarge.

Using nmtui: summary

Click the image to enlarge.

The console-network part is already operational because the enp13s0f0 interface was used from the OS installation to host the base IP address (192.168.10.160). This is the only card that is used directly.

For the other configurations, there are no IPs to assign because they will be used through virtual interfaces that will have the final IPs.

Once the profiles are declared with nmtui, we can switch to its CLI equivalent, which is nmcli, to simplify the configuration of these profiles that we just created:

nmcli connection modify data-network ipv4.method disabled ipv6.method ignore nmcli connection modify dmz-network ipv4.method disabled ipv6.method ignore
Using nmcli

Click the image to enlarge.

However, one interface is missing: the one attached to VLAN 6. We need to "derive" it from the enp8s0 card to create the enp8s0.6 interface in a vlan-enp8s0.6 profile

We also use nmcli for this:

nmcli connection add type vlan ifname enp8s0.6 dev enp8s0 id 6 nmcli connection modify vlan-enp8s0.6 ipv4.method disabled ipv6.method ignore nmcli connection up vlan-enp8s0.6
Creating the VLAN interface

Click the image to enlarge.

It is necessary to ensure that all our interfaces and associated configurations are OK.

nmcli connection show
Checking network profiles

Click the image to enlarge.

There is still one small issue to resolve, again due to Realtek... Some features of the card cause problems with how we want to use it, even with the new driver.

This is the acceleration of VLANs, a feature intended to reduce CPU load and utilize the card's hardware in VLAN management. However, here it is counterproductive because it simply doesn't allow proper use of macvtap.

Therefore, you need to disable this support, again using nmcli:

nmcli connection modify data-network ethtool.feature-rxvlan off nmcli connection modify data-network ethtool.feature-txvlan off
Disabling hardware acceleration for VLAN management

Click the image to enlarge.

You can verify that the feature is disabled with the command ethtool -k enp8s0 | grep vlan

Checking the status of the function

Click the image to enlarge.

(As a reminder, the data-network profile is associated with the Realtek enp8s0 card. Note that disabling this may not be necessary on a non-Realtek card, but it can help if you encounter VLAN problems).

Installing KVM

These are the final steps regarding this section on prerequisites: installing KVM and the dependencies required for virtualization.

First, make sure you have compatible hardware, especially a CPU with the instructions that have been mandatory for all hypervisors for a long time. This is the case for all modern processors, but sometimes the option is not enabled in the motherboard's BIOS.

To check, use the command lscpu | grep Virtualization.

Checking CPU virtualization support

Click the image to enlarge.

You should get a positive response, which may vary depending on your CPU brand (Intel or AMD) (Intel VT-x / AMD-V). If nothing appears, check your motherboard's BIOS settings in the processor options.

Once this check is complete, you can proceed with installing KVM using the following commands:

dnf install qemu-kvm libvirt virt-install virt-manager virt-viewer edk2-ovmf swtpm qemu-img guestfs-tools libosinfo tuned
Installing KVM

Click the image to enlarge.

Of course, I am using the dnf package manager here because I am on a "Red Hat-like" OS; adapt it to your system.

Make sure that libvirtd starts and is enabled at boot:

systemctl start libvirtd systemctl enable --now libvirtd systemctl status libvirtd
Starting the libvirtd service

Click the image to enlarge.

I also encourage you to associate your user with the libvirt and kvm groups to allow them to deploy VMs. Even if this isn't used on the Kubernetes side, you might need it for debugging purposes.

usermod -a -G libvirt votre_user usermod -a -G kvm votre_user

Check that the KVM module is loaded: lsmod | grep kvm

Checking KVM execution

Click the image to enlarge.

Conclusion

At this stage of deployment, I can't help but compare this first experience with my early days with VMware more than 10 years ago. Like the historical hypervisor that has become a target for many, kubevirt seems to require certain rigor in choosing hardware, specifically network cards.

KVM already has its own limitations, but adding multiple CNI layers doesn't help. This is also an important lesson to remember: with Kubevirt, you are working within the K8S logic of modularity and assembling many third-party components that share common standards, all built around Kubernetes. It's like in IT services; we work better as a team :).

We have now reached the end of this first article. There is already a lot of fundamental knowledge to absorb, and it is best to proceed step by step. For those who want to continue (now or later), the next part of the adventure can be found here