Kubevirt - Part 1: Definition and Networking

In short
  • New KubeVirt series, more comprehensive, which replaces the deprecated V1 articles.
  • A reminder of how KubeVirt works.
  • The target of the tutorial and network configuration of the host server.
  • Third-party prerequisites; Ansible role available.

Introduction

I have already written three articles about KubeVirt to share my first experience with this product, which is designed to manage and run virtual machines under Kubernetes.

Unfortunately, after several months of use (and difficulties), I realized that the architecture and methodology used are not stable.

I encountered a lot of problems, especially with the network layer. Therefore, I decided to create new tutorials, which are more comprehensive and associated with more efficient component choices.

During my initial installation, my main mistake was turning to an architecture that was in development, considered the most performant, but not necessarily stable.

I made things complicated for myself, forcing me to activate features at the KubeVirt level that were still being tested.

KubeVirt itself is still under development and is still in the incubation phase by the Cloud Native Computing Foundation (CNCF). It wasn't the best idea to try to deploy it with unfinished components... especially to achieve supposed additional performance that was ultimately useless in my use case (as in many others).

New Approach

I am going to start from scratch this time, using the good old bridge for network management, as well as the Longhorn storage layer, to reach the target of a multinode Kubevirt cluster.

I will remain on a single physical node for now, but which can be easily extended later.

Several articles will illustrate my installation:

My previous articles will remain online in case anyone finds them useful, especially regarding the use of macvtap. However, they are now deprecated in favor of the newly written and updated articles.

KubeVirt, A Reminder (or not)

To begin, I will cover much of what I have already explained about KubeVirt.

KubeVirt is an application extension for Kubernetes that allows it to orchestrate the execution of virtual machines, just as it natively does for containers.

The idea is to reuse the same object-oriented logic as K8S to extend its API and give it the ability to declare and manage virtual machines.

Red Hat initiated the project in 2017 before handing it over to the CNCF, where it is still considered an incubating project at the time of writing this article.

Project Status

Click the image to enlarge.

Please note that Red Hat already offers a commercial implementation through its OpenShift platform.

Initially, KubeVirt remained relatively obscure. However, the gradual decline in interest in VMware since its acquisition by Broadcom, coupled with the unprecedented increase in associated licensing costs, has brought alternative virtualization solutions like KubeVirt (as well as Proxmox and XCP-NG) into sharper focus.

Furthermore, behind KubeVirt lie well-known components: KVM and QEMU. These are proven solutions that have been implemented for a long time, especially by major cloud providers for running VMs.

Now, unlike ready-made solutions such as Proxmox or XCP-ng, outside of the OpenShift offering, implementing KubeVirt can still be somewhat unpredictable in certain contexts and with specific configurations.

The main challenge, but also the most fascinating aspect of KubeVirt, is integrating Kubernetes logic into the world of virtualization. Deploying a VM by combining objects described in YAML files is not necessarily easy to understand.

Moreover, when starting from a vanilla Kubernetes installation, as I am doing, there are quite a few additional components to deploy and configure.

Fortunately, as with K8S, installations and deployments are becoming increasingly simple and assisted, in part thanks to the help of AI, even though this can sometimes lead to errors due to the relatively recent adoption of KubeVirt for certain uses.

Target and objectives of the tutorial

My experiment aims to set up an initial Kubernetes node that serves as both a control plane and a worker, on which I will deploy an OPNsense VM acting as a firewall router between two networks in my lab.

The purpose of this VM is to combine several needs that are often encountered in virtualization:

  • Persistent storage compatible with moving VMs from one server to another
  • Multiple virtual network interfaces via the declaration of virtual switches within the platform.

In the end, I should have a VM capable of being migrated to a future node that is easy to set up, assuming that I have already installed all the necessary prerequisites for KubeVirt. This includes the basics of a Kubernetes cluster capable of running containerized applications and VMs.

Architecture

Here is the target diagram describing the components involved.

Diagram of components for KubeVirt

Click the image to enlarge.

The following table defines the role of each component.

Application Role Usage
KVM Type I hypervisor integrated into the Linux kernel Executes the VMs
QEMU Emulation solution Provides emulation and device management for the VMs
libvirt VM management API Provides the interaction layer with the VMs
KubeVirt K8S controller and object collection Integrates VM management into Kubernetes and orchestrates their execution via KVM through libvirt
Cilium Network connectivity for pods/VMs Provides the primary network connectivity to the VMs
Multus Adds multiple network interfaces to a K8S object Allows adding additional network interfaces to the VMs
Linux Bridge L2 network solution integrated into the Linux kernel Attaches a physical interface to the VM

Hardware

The witness server used is a physical machine with the following characteristics:

  • OS: Rocky Linux 10.1
  • 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 4 port Intel I350 Gigabit card

I would like to draw your attention to the choice of network card. During my initial installation, I only had Realtek chipsets available.

This is clearly a bad choice. Even though I was able to modify the default drivers to use versions more recent than those initially integrated into the OS, Realtek is not a good hardware option for exploiting advanced network features on a Linux OS.

Prioritize Intel controllers, which are much better supported.

Network configuration

Logic

In my case, my Realtek 2.5Gb card will primarily serve as an administration interface for my server and an SSH entry point. It will also carry the main IP address of the K8S API, but it will not be used for the KubeVirt interfaces.

For this purpose, I reserve my ports using the Intel chipset.

Here is the network logic diagrammed.

Detailed diagram of the KubeVirt network target

Click the image to enlarge.

The enp13s0f0 and enp13s0f3 ports will serve as a bridge interface to create virtual switches, which I will connect my VMs to.

By default, enp13s0f3 will only serve a single network, providing access to my "First" DMZ, which is directly connected to my external router.

enp13s0f0 will offer two VLANs:

  • The default VLAN connected to my standard LAN
  • VLAN 6, connected to my intermediate DMZ, which I have called VLAN WEB, and intended for hosting servers accessible from the outside.

My OPNsense VM will use two virtual interfaces, one associated with my internal VLAN and the other with my VLAN WEB.

Implementation

Let's move on to configuring the interfaces.

I will not detail the section concerning the interface enp8s0 dedicated to the server's default IP address (192.168.10.160). This is configured during OS installation and does not have any special features.

First, we remove the default configurations associated with the interface dedicated to KubeVirt:

sudo nmcli connection delete enp13s0f0
sudo nmcli connection delete enp13s0f3
Removing default network configurations

Click the image to enlarge.

Network component selection

Now you need to choose the technology used for creating virtual interfaces. Three options are available.

Feature Linux Bridge Macvtap SR-IOV
Type Software (L2 Switch) Software (Optimized Driver) Hardware (Virtualization NIC)
Performance Average (CPU Overhead) Very Good Maximum (Native)
Host CPU Usage High (the host routes everything) Medium/Low None (Offload hardware)
Setup Infrastructure Configure a br0 Nothing (just interface) Drivers + Device Plugin K8s + BIOS
Isolation Low (the host sees everything) Medium High (Bypasses the host OS)
Host <-> VM Communication ✅ Works ❌ No (unless using tricks) ❌ No
Live Migration ✅ Easy / Standard ✅ Possible ⚠️ Complex (requires advanced configuration)
Use Case Dev, General Purpose, Debug General Production, Bare Metal Telco (5G), Trading HFT, NFV

SR-IOV, although it is the most performant method, it implies a configuration complexity and specific hardware requirements. My Intel card supports it, but I am exposed to potential future limitations when migrating VMs live.

Previously, I used the macvtap feature, which offers greater hardware flexibility, but I encountered several problems when integrating it with KubeVirt, particularly in terms of stability. Perhaps I did something wrong; however, if I don't completely abandon this approach, I prefer to move towards the Linux Bridge mode.

This is certainly the least performant and oldest solution, but it is flexible, stable, and perfectly supported by KubeVirt.

The bridge mode is used in many configurations, and except for very advanced performance requirements, the CPU overhead and latency are usually perfectly acceptable for common needs.

Interface configuration

Let's configure this starting with the default LAN network.

sudo nmcli con add type bridge con-name br-lan ifname br-lan ipv4.method disabled ipv6.method disabled bridge.stp no
sudo nmcli con add type ethernet con-name br-lan-slave-1 ifname enp13s0f0 master br-lan
sudo nmcli con up br-lan
Configuring the LAN interface

Click the image to enlarge.

The interface br-lan is now UP.

Next, we will configure VLAN 6. We start by creating the VLAN 6 interface itself:

sudo nmcli con add type vlan con-name vlan-6 dev enp13s0f0 id 6

Then, we create the bridge interface that connects to it:

sudo nmcli con add type bridge con-name br-web ifname br-web ipv4.method disabled ipv6.method disabled bridge.stp no
sudo nmcli connection modify vlan-6 master br-web slave-type bridge
sudo nmcli connection modify vlan-6 ipv4.method disabled ipv6.method disabled
sudo nmcli con up br-web
Configuring the VLAN WEB interface

Click the image to enlarge.

Now the interface br-web is operational.

Finally, we have the DMZ interface, which uses the same principles as the default LAN interface, but using enp13s0f3 as the physical source interface

sudo nmcli con add type bridge con-name br-dmz ifname br-dmz ipv4.method disabled ipv6.method disabled bridge.stp no
sudo nmcli con add type ethernet con-name br-dmz-slave-1 ifname enp13s0f3 master br-dmz
sudo nmcli con up br-dmz
Configuring the DMZ interface

Click the image to enlarge.

The DMZ interface is up.

Just to make sure everything is OK, let's run another command to bring up the bridge interfaces:

sudo nmcli connection up br-lan-slave-1
sudo nmcli connection up br-dmz-slave-1
sudo nmcli connection up vlan-6
Bringing up all interfaces

Click the image to enlarge.

Next, we ensure that everything is configured correctly with the nmcli connection show command

Controlling the interfaces

Click the image to enlarge.

That's a good thing accomplished.

Third-party prerequisites

We can now proceed with the third-party prerequisites necessary for our Kubernetes and KubeVirt installation.

To do this, I will reuse my Ansible playbooks that I used for my Kubernetes cookbook, slightly modified.

I won't go into detail about everything done in these playbooks, but generally:

  • We deploy a number of necessary packages
    • kubeadm
    • wget
    • tar
    • kubectl
    • kubelet
    • cryptsetup
    • crun
    • jq
    • git
    • device-mapper-multipath
  • We uninstall unnecessary packages or those that may conflict with our configuration
    • docker
    • containerd
  • We ensure the presence of certain kernel modules:
    • overlay
    • br_netfilter
    • kvm
    • vhost_net
    • dm_crypt
  • We install and configure containerd directly from the source code so that it can be used as a CRI (Container Runtime Interface) for Kubernetes (it is important to note that with RockyLinux 10, runc has become crun).

As a reminder, Containerd is the high-level runtime that runs as a daemon and interacts with Kubernetes agents, known as kubelets. It relies on a lower-level binary, historically runc, to manage containers.

Runc is an OCI (Open Container Interface) compliant runtime, which is the standard for containerization. Developed in Go, it has been replaced by a version named crun, written in C, which is considered faster and more optimized across all Red Hat operating system families from version 10.

Tool Level Role Language Performance Typical Usage
Containerd High Manages images, Kubernetes API Go N/A (It is a daemon) Standard for K8s
Runc Low Creates the Linux process Go Standard 99% of K8s clusters
Crun Low Creates the Linux process C High (+ fast, - RAM) Edge, Serverless, Fedora/RHEL

It will be necessary to adapt the Containerd configuration so that it can use crun instead of runc. You can find a compatible configuration here.

We adjust kernel parameters by adding a file 99-kubernetes.conf in /etc/sysctl.d/

  
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net/bridge/bridge-nf-call-arptables = 1
fs.inotify.max_user_watches = 1048576
fs.inotify.max_user_instances = 8192
    

We prepare the Kubernetes-specific configuration files, including the kubeadm.conf file, which we will pass to kubeadm to initialize the cluster.

  
---
# PARTIE 1 : Configuration du noeud initial (Master)
apiVersion: kubeadm.k8s.io/v1beta4
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: "192.168.10.160"
  bindPort: 6443
nodeRegistration:
  criSocket: "unix:///var/run/containerd/containerd.sock"
  kubeletExtraArgs:
  - name: "node-ip"
    value: "192.168.10.160"

---
# PARTIE 2 : Configuration du Cluster
apiVersion: kubeadm.k8s.io/v1beta4
kind: ClusterConfiguration
kubernetesVersion: "1.34.2"
clusterName: "rubikub"
controlPlaneEndpoint: "rubikub.coolcorp.priv:6443"
networking:
  dnsDomain: cluster.local
  podSubnet: "10.11.0.0/16"
  serviceSubnet: "10.12.0.0/16"
apiServer:
  certSANs:
  - "192.168.10.160"
  - "rubikub.coolcorp.priv"
  - "127.0.0.1"
  - "localhost"
scheduler: {}
controllerManager: {}

---
# PARTIE 3 : Configuration du Kubelet
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
failSwapOn: true
authentication:
  anonymous:
    enabled: false
    

192.168.10.160 corresponds to the IP address of my server and the IP address associated with the K8S API on the enp8s0 interface.

If you would like to learn more about the use of this file and its parameters, please feel free to refer to my article from my Kubernetes cookbook.

We also process the cilium-values.yaml file associated with the Cilium Container Network Interface (CNI).

  
kubeProxyReplacement: true
k8sServiceHost: 192.168.10.160
k8sServicePort: 6443
cni:
  # Empêche Cilium de prendre le contrôle total du dossier /etc/cni/net.d
  # Cela permet à Multus de rester le "maître" et d'appeler Cilium comme plugin délégué
  exclusive: false
ipam:
  mode: "cluster-pool"
  operator:
    clusterPoolIPv4PodCIDRList:
      - "10.13.0.0/16"
# Configuration Hubble (Visualisation)
hubble:
  relay:
    enabled: true
  ui:
    enabled: true
    frontend:
      server:
        ipv6:
          enabled: false
  tls:
    auto:
      enabled: true
      method: helm
      certValidityDuration: 1095

cgroup:
  autoMount:
    enabled: false
   

Feel free to browse my Kubernetes cookbook to learn more.

It is important to note that the kubeadm configuration file has evolved over the versions of Kubernetes. The version presented here is perfectly compatible with K8S 1.34, the target version of this tutorial (as of the writing of this article, version 1.35 has just been released, and this configuration file should also be usable with that version).

For those who wish to, the entire Ansible role playbook responsible for creating the configuration files and processing prerequisites is available here.

We will stop here for this first part. The next part is available via the following URL, with the initialization of Kubernetes/KubeVirt and the implementation of Cilium/Multus.