Cloud Computing 23 min read

KubeVirt: Integrating Virtual Machines into Kubernetes – Architecture, Operations, and SDK Usage

This article explains how KubeVirt extends Kubernetes to manage virtual machines, covering the background of OpenStack‑to‑K8s migration, technical selection, KubeVirt architecture, CRDs, components, common operations, storage and networking choices, SDK usage, and practical deployment experiences within a private cloud platform.

360 Tech Engineering
360 Tech Engineering
360 Tech Engineering
KubeVirt: Integrating Virtual Machines into Kubernetes – Architecture, Operations, and SDK Usage

KubeVirt is a Kubernetes plug‑in that enables the scheduling and lifecycle management of traditional virtual machines alongside containers by leveraging custom resources (CRDs) and other native Kubernetes features.

The author describes the motivation behind moving from a dual‑platform (OpenStack for VMs and Kubernetes for containers) to a unified Kubernetes‑centric approach, citing resource duplication, overlapping skill sets, and the growing dominance of container workloads.

Key technical choices include adopting KubeVirt as the primary VM management solution, evaluating alternatives such as Virtlet and Kata, and deciding against using OpenStack for container orchestration.

KubeVirt Overview

KubeVirt provides a set of CRDs that represent virtual machine definitions (VM) and instances (VMI). These resources are managed through an operator pattern, allowing VM lifecycle actions via the Kubernetes API.

CRD Example

type DomainManager interface {
//SyncVMI 为创建虚拟机
SyncVMI(*v1.VirtualMachineInstance, bool, *cmdv1.VirtualMachineOptions) (*api.DomainSpec, error)
//暂停VMI
PauseVMI(*v1.VirtualMachineInstance) error
//恢复暂停的VMI
UnpauseVMI(*v1.VirtualMachineInstance) error
//删除VMI
DeleteVMI(*v1.VirtualMachineInstance) error
//迁移VMI
MigrateVMI(*v1.VirtualMachineInstance, *cmdclient.MigrationOptions) error
//检查卷是否可共享用于热迁移
func (d *VirtualMachineController) checkVolumesForMigration(vmi *v1.VirtualMachineInstance) (blockMigrate bool, err error) { … }

Components

KubeVirt consists of several components that run as pods in the cluster: virt-api , virt-controller , virt-handler , and virt-launcher . These components delegate scheduling to Kubernetes while handling VM‑specific tasks such as libvirt interaction.

Common Operations

[root@openstack825 ~]# kubectl get vmi -o wide
NAME                          AGE   PHASE   IP             NODENAME        LIVE-MIGRATABLE
test100.foo.demo.example.com   8d   Running 192.168.10.30  10.10.67.244   True

Typical issues encountered include data loss on VM restart, IP changes after live migration, slow image import, and migration constraints related to storage sharing.

Storage Options

KubeVirt supports several disk types: cloudInitNoCloud (cloud‑init data via ConfigMap), dataVolume (auto‑imported PVC from HTTP or existing PVC), and plain PersistentVolumeClaim . For non‑persistent workloads, ephemeral and containerDisk are used, often backed by a Ceph RBD storage class.

devices:
disks:
- disk:
bus: virtio
name: cloudinit
cloudInitNoCloud:
userData: |
#cloud-config
password: kubevirt

Ceph is employed as the backend storage, using the RBD CSI driver to provide RWX block volumes required for live migration.

Networking

KubeVirt relies on the underlying Kubernetes network. The author chose Kube‑OVN (an OVN‑based CNI) to provide L2 VLAN underlay, fixed IP allocation, and integration with existing OpenStack networking concepts.

SDK Usage

KubeVirt offers Python and Go SDKs. The Python SDK is used in the examples, showing how to create an ApiClient , instantiate DefaultApi , and perform operations such as creating, deleting, listing, starting, stopping, and renaming VMs.

import kubevirt
def get_api_client(host):
api_client = kubevirt.ApiClient(host=host, header_name="Content-Type", header_value="application/json")
return api_client
api_client = get_api_client(host="http://127.0.0.1:8001")
api_instance = kubevirt.DefaultApi(api_client)

Custom extensions were added to fix missing parameters in the rename API, demonstrating how to adapt the SDK to real‑world needs.

Ultron Platform Integration

The private cloud management platform "Ultron" now supports KubeVirt VMs with the same user experience as OpenStack, allowing seamless migration of workloads.

Conclusion

KubeVirt provides a viable solution for private‑cloud virtualization by unifying VM and container management under Kubernetes, though it may still face challenges in public‑cloud scenarios due to inherent IaaS limitations.

SDKkubernetesstorageNetworkingVirtualizationCephCRDKubeVirt
360 Tech Engineering
Written by

360 Tech Engineering

Official tech channel of 360, building the most professional technology aggregation platform for the brand.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.