Create a KubeVirt VM Using a Precreated PVC
You can create a KubeVirt virtual machine (VM) that references an existing PersistentVolumeClaim (PVC). This workflow lets you provision and verify storage before creating the VM, reuse a PVC across VM definitions, or manage the PVC lifecycle independently of the VM.
When you reference a Fusion-backed PVC in a VM, the Portworx Fusion Controller detects the reference, creates a corresponding FusionWorkload custom resource (CR) to track the VM storage, and provisions the volume on the appropriate FlashArray based on the associated Fusion preset.
This workflow supplements the DataVolumeTemplate workflow described in Create a KubeVirt VM Using a Fusion Preset. Existing VMs that use DataVolumeTemplate continue to work without changes.
Prerequisites
Before you begin, ensure that the following requirements are met:
- Portworx Fusion Controller is enabled. For more information, see Enable Portworx Fusion Controller.
- A Fusion preset is available. For more information, see Create a Fusion Preset.
PVC compatibility requirements
Before referencing a PVC in a VM, ensure that the PVC meets the following requirements:
| Requirement | Description |
|---|---|
| StorageClass | The PVC must use the same StorageClass as the VM's existing PVCs. |
| Access mode | The access mode matches the disk usage. Use ReadWriteOnce (RWO) for a single-node disk or ReadWriteMany (RWX) for disks on VMs that use live migration. |
| Volume mode | The volume mode matches the VM disk requirements. Use Block for raw block disks or Filesystem for file system-backed disks. |
| Status | The PVC is in the Pending state before the VM references it. |
| Namespace | The PVC and VM are in the same namespace. |
A KubeVirt VM must use a single RWX volume type for all its disks. Do not mix volume types on the same VM. Mixing volume types can cause node drains to stall during OpenShift Container Platform or Portworx upgrades.
Create a VM using a precreated PVC
To create a VM that uses an existing PVC as a disk:
-
Create a PVC that references a Fusion-backed
StorageClass:apiVersion: v1kind: PersistentVolumeClaimmetadata:name: fusion-vm-disknamespace: portworxspec:storageClassName: fleet-testing-gold-tieraccessModes:- ReadWriteOnceresources:requests:storage: 50GiReplace
fleet-testing-gold-tierwith theStorageClassgenerated from your Fusion preset. -
Apply the PVC:
kubectl apply -f fusion-vm-disk.yaml -
Create the VM and reference the PVC as a disk by using a
persistentVolumeClaimvolume source:apiVersion: kubevirt.io/v1kind: VirtualMachinemetadata:name: fusion-vmnamespace: portworxspec:running: truetemplate:spec:domain:devices:disks:- name: os-diskdisk:bus: virtiovolumes:- name: os-diskpersistentVolumeClaim:claimName: fusion-vm-disk -
Apply the VM:
kubectl apply -f fusion-vm.yaml -
Verify that the PVC is in the
Boundstate:kubectl get pvc fusion-vm-disk -n portworxVerify that the
STATUScolumn showsBound:NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEfusion-vm-disk Bound pvc-a1b2c3d4 50Gi RWO fleet-testing-gold-tier 30s -
Verify that the VM is running:
kubectl get vm fusion-vm -n portworxVerify that the
STATUScolumn showsRunning.
Verify the Fusion workload
When the Fusion Controller detects the PVC reference, it creates a FusionWorkload CR to represent and track the VM storage.
To list the Fusion workloads, run:
kubectl get fusionworkload -n <namespace>
To view provisioning details and events for the workload, run:
kubectl describe fusionworkload <workload-name> -n <namespace>
Replace <namespace> with the namespace where the VM and PVC reside and <workload-name> with the name of the FusionWorkload CR associated with the VM.
If provisioning fails, the VM remains in the Provisioning state. Check the events for the corresponding FusionWorkload CR to determine the cause.
The PVC has an independent lifecycle from the VM. Deleting the VM does not delete a precreated PVC. Delete the PVC separately when you no longer need the storage.