Skip to main content

Overview

The KubeVirt class represents the primary resource for deploying and configuring the KubeVirt virtualization platform in an OpenShift cluster. It manages all KubeVirt infrastructure components and provides cluster-wide virtualization configuration.

Class Definition

from ocp_resources.kubevirt import KubeVirt

class KubeVirt(NamespacedResource):
    api_group = NamespacedResource.ApiGroup.KUBEVIRT_IO

Constructor

certificate_rotate_strategy
dict
Configuration for certificate rotation strategy.
configuration
dict
KubeVirt configuration settings, equivalent to the virt-config ConfigMap.
customize_components
dict
Customization options for KubeVirt components.
image_pull_policy
string
Image pull policy for KubeVirt containers: "Always", "IfNotPresent", or "Never".
image_pull_secrets
list
List of image pull secrets for accessing private container registries.
image_registry
string
Container image registry to pull KubeVirt images from. Defaults to the operator’s registry.
image_tag
string
Tag for KubeVirt container images. Defaults to the operator’s image tag.
infra
dict
Node selectors and tolerations for KubeVirt infrastructure components.
monitor_account
string
Prometheus service account name for monitoring KubeVirt endpoints. Defaults to "prometheus-k8s".
monitor_namespace
string
Namespace where Prometheus is deployed. Defaults to "openshift-monitor".
product_component
string
Value for the apps.kubevirt.io/component label. Defaults to "kubevirt" if not specified.
product_name
string
Value for the apps.kubevirt.io/part-of label. Useful when KubeVirt is part of a larger product.
product_version
string
Value for the apps.kubevirt.io/version label. Defaults to KubeVirt’s version if not specified.
service_monitor_namespace
string
Namespace for deploying ServiceMonitor objects. If not set, uses monitor_namespace.
uninstall_strategy
string
Controls whether KubeVirt can be deleted when workloads are present. Prevents accidental data loss.
workload_update_strategy
dict
Cluster-wide strategy for handling automated workload updates.
workloads
dict
Node selectors and tolerations that apply to KubeVirt workload pods (VMs).

Usage Examples

from ocp_resources.kubevirt import KubeVirt
from ocp_resources.resource import get_client

client = get_client()

# Deploy KubeVirt with default settings
kubevirt = KubeVirt(
    client=client,
    name="kubevirt",
    namespace="openshift-cnv"
)

kubevirt.create()
kubevirt.wait_for_condition(
    condition="Available",
    status="True",
    timeout=600
)

Configuration Options

Feature Gates

Common feature gates that can be enabled in the configuration parameter:
  • LiveMigration: Enable live migration of VMs between nodes
  • HotplugVolumes: Allow hotplugging of volumes to running VMs
  • CPUManager: Enable CPU manager integration
  • GPU: Enable GPU passthrough support
  • HostDevices: Enable host device passthrough
  • Snapshot: Enable VM snapshot support
  • HotplugNICs: Allow hotplugging of network interfaces

Network Configuration

Network-related configuration options:
configuration={
    "networkConfiguration": {
        "defaultNetworkInterface": "bridge",  # or "masquerade"
        "permitSlirpInterface": True,
        "permitBridgeInterfaceOnPodNetwork": False
    }
}

Developer Configuration

Developer and debugging options:
configuration={
    "developerConfiguration": {
        "featureGates": ["FeatureName"],
        "logVerbosity": {
            "virtAPI": 2,
            "virtController": 2,
            "virtHandler": 2,
            "virtLauncher": 2
        }
    }
}

Status Conditions

The KubeVirt resource reports the following conditions:
  • Available: All KubeVirt components are ready
  • Progressing: KubeVirt is being deployed or updated
  • Degraded: One or more components are not functioning properly
# Check if KubeVirt is available
if kubevirt.instance.status.conditions:
    for condition in kubevirt.instance.status.conditions:
        if condition.type == "Available" and condition.status == "True":
            print("KubeVirt is available")

VirtualMachine

Create and manage virtual machines

DataVolume

Manage persistent storage for VMs

Notes

The KubeVirt resource is typically deployed by the OpenShift Virtualization operator. Manual creation is only needed for custom deployments or advanced configurations.
Changing certain configuration options (like image_registry or image_tag) may trigger a rolling update of all KubeVirt components and could cause brief service interruptions.
Use the uninstall_strategy parameter set to "BlockUninstallIfWorkloadsExist" to prevent accidental deletion of KubeVirt when VMs are still running.

Build docs developers (and LLMs) love