A containerdisk gives you a throwaway VM. For a VM that keeps its disk, the image has to be copied into a PersistentVolumeClaim. The Containerized Data Importer (CDI) does that. It is part of OpenShift Virtualization and an add-on for plain KubeVirt.

What you’ll need

  • KubeVirt with CDI installed
  • A default StorageClass, or one you name in the manifests

Option 1: Import the qcow2 over HTTPS

Each image is published as a qcow2 file on boxes.cloudsoe.com. A dataVolumeTemplates entry tells CDI to download it into a new PVC when the VM is created:

apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: ubuntu-24-04
spec:
  runStrategy: Always
  dataVolumeTemplates:
    - metadata:
        name: ubuntu-24-04-root
      spec:
        source:
          http:
            url: https://boxes.cloudsoe.com/kubevirt/ubuntu-24.04/202611.14.0/ubuntu-24.04-amd64.qcow2
        storage:
          resources:
            requests:
              storage: 20Gi
  template:
    spec:
      domain:
        cpu:
          cores: 1
        memory:
          guest: 2Gi
        devices:
          disks:
            - name: rootdisk
              disk:
                bus: virtio
            - name: cloudinit
              disk:
                bus: virtio
          interfaces:
            - name: default
              masquerade: {}
      networks:
        - name: default
          pod: {}
      volumes:
        - name: rootdisk
          dataVolume:
            name: ubuntu-24-04-root
        - name: cloudinit
          cloudInitNoCloud:
            userData: |
              #cloud-config
              ssh_authorized_keys:
                - ssh-ed25519 AAAA... [email protected]
kubectl apply -f ubuntu-24-04.yaml
kubectl get datavolume ubuntu-24-04-root --watch

The VM starts when the DataVolume reaches Succeeded. The PVC is 20 Gi here, and the root filesystem grows to fill it on first boot. Change storage to the size you need.

The URL contains the version, so the VM is always built from the same file. Current URLs and checksums are on each image page.

Option 2: Import from the registry

If your cluster can reach quay.io but not boxes.cloudsoe.com, import the containerdisk instead. Replace the source block:

        source:
          registry:
            url: docker://quay.io/cloudsoe/ubuntu-24.04:202611.14.0

Keep a golden image current with DataImportCron

Downloading the image for every VM is slow. A DataImportCron imports it once into a PVC, repeats the import when a new build is published, and exposes the newest copy as a DataSource. New VMs clone from that.

apiVersion: cdi.kubevirt.io/v1beta1
kind: DataImportCron
metadata:
  name: cloudsoe-ubuntu-24-04
  namespace: golden-images
spec:
  schedule: "0 3 * * 1"
  managedDataSource: cloudsoe-ubuntu-24-04
  garbageCollect: Outdated
  importsToKeep: 2
  template:
    spec:
      source:
        registry:
          url: docker://quay.io/cloudsoe/ubuntu-24.04:latest
      storage:
        resources:
          requests:
            storage: 20Gi

The schedule above checks the latest tag every Monday at 03:00. When its digest has changed, CDI imports the new build and points the DataSource at it. The two newest imports are kept.

A VM then clones the DataSource:

  dataVolumeTemplates:
    - metadata:
        name: ubuntu-24-04-root
      spec:
        sourceRef:
          kind: DataSource
          name: cloudsoe-ubuntu-24-04
          namespace: golden-images
        storage:
          resources:
            requests:
              storage: 20Gi

The rest of the VirtualMachine is the same as in Option 1.

Check an import

kubectl get datavolume
kubectl get dataimportcron -n golden-images
kubectl get datasource -n golden-images

If a DataVolume stays in ImportInProgress, read the importer pod’s log:

kubectl logs -l cdi.kubevirt.io=importer --tail=50