Deploying KubeVirt on Kubernetes: Run Virtual Machines and Containers Side-by-Side

DevOps tutorial - IT technology blog
DevOps tutorial - IT technology blog

Architectural Comparison: Traditional Silos vs. Unified Virtualization

Most infrastructure teams maintain two separate platforms. You likely have a hypervisor stack like VMware vSphere, Proxmox, or OpenStack for monolithic databases and legacy Windows systems, alongside an EKS, GKE, or bare-metal Kubernetes cluster for containerized microservices.

This split burns engineering time. Your team ends up managing two monitoring stacks (Prometheus alongside vRealize), duplicate networking overlays, separate backup software, and distinct IAM policies across both environments.

KubeVirt bridges this divide. It installs Custom Resource Definitions (CRDs) and controllers that schedule and run standard KVM virtual machines inside regular Kubernetes Pods. You no longer need to rewrite every legacy ERP system or proprietary network appliance to get declarative orchestration.

Here is how the common operational patterns stack up:

  • Two-Platform Architecture: Independent server racks, isolated top-of-rack switches, and disconnected backup tooling (such as Veeam for VMs and Velero for Kubernetes). Developers waste time bouncing between vCenter GUIs and kubectl prompts.
  • Container-Only Refactoring: Forcing stateful monoliths into lightweight OCI containers. This sounds great in design reviews. In practice, legacy applications often rely on custom kernel modules, strict broadcast protocols, or raw block storage that break container assumptions.
  • KubeVirt Unified Model: A single declarative API, unified GitOps through tools like ArgoCD or Flux, and shared storage classes backed by standard CSI drivers. Virtual machines run as native Kubernetes workloads.

Evaluating Trade-Offs: The Pros and Cons

Consolidating VMs under the Kubernetes scheduler simplifies lifecycle management, but it demands careful capacity planning.

The Advantages

  • Unified Control Plane: Define VM specs, CPU pins, and disk boundaries using standard YAML manifests, Helm, or Kustomize alongside your application microservices.
  • Direct In-Cluster Networking: Containers and VMs talk directly across the Pod network with sub-millisecond latency. You avoid extra hops through external ingress controllers or hardware firewalls while keeping Kubernetes NetworkPolicy rules intact.
  • Consolidated Compute: Running both workloads on the same bare-metal nodes eliminates the compute tax of idle hypervisor reserves. Teams frequently reclaim 20% to 35% in unallocated CPU and RAM.
  • Automated Day-2 Maintenance: When a worker node requires a kernel patch, the virt-controller automatically live-migrates running guest instances to healthy nodes with zero workload downtime.

The Trade-Offs

  • Nested Virtualization Penalties: On public cloud instances without bare-metal hardware access, nested hypervisor translation can add a 15% to 30% CPU overhead. Bare-metal nodes running native KVM deliver near-bare-metal compute speeds.
  • Demanding Storage Architecture: Zero-downtime live migration requires shared block storage with ReadWriteMany (RWX) access. Storage systems like Ceph RBD or fast NVMe-oF SANs are required to sustain steady write performance and fast failovers.
  • Operational Shift: System administrators who rely on GUI-based consoles like vCenter must adjust to GitOps workflows, virtctl terminal sessions, and headless cloud-init provisioning.

Infrastructure Baseline and Prerequisites

A resilient KubeVirt deployment requires reliable hardware virtualization and high-throughput storage.

  • Host Hardware: Dedicated bare-metal nodes with Intel VT-x or AMD-V flags enabled in firmware. For sandbox testing on AWS or GCP, provision nested-virtualization instances such as c5.metal or GCP n2-standard-8 instances with nested virtualization enabled.
  • Kubernetes Release: Kubernetes 1.28 or newer with standard Linux control plane nodes.
  • Storage Backend: A production-grade CSI driver supporting dynamic block provisioning. Rook-Ceph, Longhorn, or enterprise SAN drivers work well. Live migration strictly requires ReadWriteMany (RWX) block or filesystem support.
  • Secondary Networking (Multus CNI): While the primary flannel or Calico network handles default pod traffic, Multus lets you attach dedicated SR-IOV or Macvlan interfaces to route VM traffic directly to external corporate VLANs.

Step-by-Step Deployment Guide

Let’s install the operator, spin up the core virtualization control plane, install the CLI management utility, and boot a lightweight Alpine Linux virtual machine.

Step 1: Check Hardware Virtualization Flags

Confirm that your target nodes support KVM extensions before installing any manifests. Run this check directly on your worker node:

# Verify CPU virtualization support (Intel VT-x or AMD-V)
egrep -c '(vmx|svm)' /proc/cpuinfo

# Ensure the KVM character device exists with read/write permissions
ls -l /dev/kvm

A return count of 1 or higher confirms hardware support. If /dev/kvm is missing, verify your BIOS settings or hypervisor nested-virtualization configuration. Software emulation via QEMU is technically possible, but it is far too slow for serious workloads.

Step 2: Install the KubeVirt Operator

The operator manages the lifecycle of KubeVirt components, including virt-api, virt-controller, and node-level virt-handler daemonsets. Query the latest stable release tag and apply the operator manifest:

export KUBEVIRT_VERSION=$(curl -s https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirt/stable.txt)

# Deploy the operator CRDs and controller
kubectl apply -f "https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml"

Step 3: Trigger Component Deployment

Instantiate the control plane by applying the KubeVirt custom resource. This signals the operator to roll out daemonsets and API webhooks:

kubectl apply -f "https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml"

Monitor the rollout until all pods report a Running status:

kubectl get pods -n kubevirt -w

Step 4: Set Up the virtctl CLI

Standard kubectl commands work for basic object inspection, but the dedicated virtctl tool adds support for interactive serial consoles, VNC graphic tunneling, VM stop/start triggers, and live migrations.

# Download and install the matching binary to your path
curl -L -o virtctl "https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64"
chmod +x virtctl
sudo install virtctl /usr/local/bin/

Step 5: Define and Launch a Test VM

In KubeVirt, a VirtualMachine (VM) manifest defines the state and template, while a VirtualMachineInstance (VMI) represents the active compute process. Save this manifest as alpine-vm.yaml:

apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: alpine-workload
  namespace: default
spec:
  running: true
  template:
    metadata:
      labels:
        kubevirt.io/domain: alpine-workload
    spec:
      domain:
        devices:
          disks:
          - disk:
              bus: virtio
            name: containerdisk
        resources:
          requests:
            memory: 512Mi
            cpu: 1
      volumes:
      - containerDisk:
          image: quay.io/containerdisks/alpine:latest
        name: containerdisk

Submit the configuration to the Kubernetes API:

kubectl apply -f alpine-vm.yaml

Step 6: Inspect and Connect to the Guest OS

Watch the instance launch. Behind the scenes, KubeVirt schedules a pod named virt-launcher-<name> that contains the isolated QEMU/libvirt execution boundary.

# Check the VM and active VMI status
kubectl get vms,vmis

# View the wrapping launcher pod
kubectl get pods -l kubevirt.io=virt-launcher

Once the status transitions to Running, open the serial console:

virtctl console alpine-workload

Hit Enter to view the Alpine Linux login prompt. The guest system is fully operational, receives its IP address directly from the pod network CIDR, respects your cluster NetworkPolicies, and runs side-by-side with your standard container deployments.

Share: