×

You can upload a local disk image into a block DataVolume by using the virtctl command-line utility.

In this workflow, you create a local block device to use as a PersistentVolume, associate this block volume with an upload DataVolume, and use virtctl to upload the local disk image into the DataVolume.

Prerequisites

About DataVolumes

DataVolume objects are custom resources that are provided by the Containerized Data Importer (CDI) project. DataVolumes orchestrate import, clone, and upload operations that are associated with an underlying PersistentVolumeClaim (PVC). DataVolumes are integrated with KubeVirt, and they prevent a virtual machine from being started before the PVC has been prepared.

About block PersistentVolumes

A block PersistentVolume (PV) is a PV that is backed by a raw block device. These volumes do not have a filesystem and can provide performance benefits for virtual machines that either write to the disk directly or implement their own storage service.

Raw block volumes are provisioned by specifying volumeMode: Block in the PV and PersistentVolumeClaim (PVC) specification.

Creating a local block PersistentVolume

Create a local block PersistentVolume (PV) on a node by populating a file and mounting it as a loop device. You can then reference this loop device in a PV configuration as a Block volume and use it as a block device for a virtual machine image.

Procedure
  1. Log in as root to the node on which to create the local PV. This procedure uses node01 for its examples.

  2. Create a file and populate it with null characters so that it can be used as a block device. The following example creates a file loop10 with a size of 2Gb (20 100Mb blocks):

    $ dd if=/dev/zero of=<loop10> bs=100M count=20
  3. Mount the loop10 file as a loop device.

    $ losetup </dev/loop10>d3 <loop10> (1) (2)
    1 File path where the loop device is mounted.
    2 The file created in the previous step to be mounted as the loop device.
  4. Create a PersistentVolume configuration that references the mounted loop device.

    kind: PersistentVolume
    apiVersion: v1
    metadata:
      name: <local-block-pv10>
      annotations:
    spec:
      local:
        path: </dev/loop10> (1)
      capacity:
        storage: <2Gi>
      volumeMode: Block (2)
      storageClassName: local (3)
      accessModes:
        - ReadWriteOnce
      persistentVolumeReclaimPolicy: Delete
      nodeAffinity:
        required:
          nodeSelectorTerms:
          - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
              - <node01> (4)
    1 The path of the loop device on the node.
    2 Specifies it is a block PV.
    3 Optional: Set a StorageClass for the PV. If you omit it, the cluster default is used.
    4 The node on which the block device was mounted.
  5. Create the block PV.

    # oc create -f <local-block-pv10.yaml>(1)
    1 The filename of the PersistentVolume created in the previous step.

Creating an upload DataVolume

Create a DataVolume with an upload data source to use for uploading local disk images.

Procedure
  1. Create a DataVolume configuration that specifies spec: source: upload{}:

    apiVersion: cdi.kubevirt.io/v1alpha1
    kind: DataVolume
    metadata:
      name: <upload-datavolume> (1)
    spec:
      source:
          upload: {}
      pvc:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: <2Gi> (2)
    1 The name of the DataVolume
    2 The size of the DataVolume
  2. Create the DataVolume:

    $ oc create -f <upload-datavolume>.yaml

Uploading a local disk image to a new DataVolume

You can use the virtctl CLI utility to upload a virtual machine disk image from a client machine to a DataVolume (DV) in your cluster. After you upload the image, you can add it to a virtual machine.

Prerequisites
  • A virtual machine disk image, in RAW, ISO, or QCOW2 format, optionally compressed by using xz or gz.

  • The kubevirt-virtctl package must be installed on the client machine.

  • The client machine must be configured to trust the OpenShift Container Platform router’s certificate.

  • A spare DataVolume that is the same size or larger than the disk that you are uploading.

Procedure
  1. Identify the following items:

    • File location of the VM disk image that you want to upload

    • Name of the DataVolume

  2. Run the virtctl image-upload command to upload your disk image. You must specify the DV name and file location. For example:

    $ virtctl image-upload --dv-name=<upload-datavolume> --image-path=</images/fedora.qcow2> (1) (2)
    1 The name of the DataVolume that you are creating.
    2 The filepath of the virtual machine disk image you are uploading.

    To allow insecure server connections when using HTTPS, use the --insecure parameter. Be aware that when you use the --insecure flag, the authenticity of the upload endpoint is not verified.

  3. To verify that the DV was created, view all DV objects:

    $ oc get dvs

CDI supported operations matrix

This matrix shows the supported CDI operations for content types against endpoints, and which of these operations requires scratch space.

Content types HTTP HTTPS HTTP basic auth Registry Upload

KubeVirt(QCOW2)

✓ QCOW2
✓ GZ*
✓ XZ*

✓ QCOW2**
✓ GZ*
✓ XZ*

✓ QCOW2
✓ GZ*
✓ XZ*

✓ QCOW2*
□ GZ
□ XZ

✓ QCOW2*
✓ GZ*
✓ XZ*

KubeVirt (RAW)

✓ RAW
✓ GZ
✓ XZ

✓ RAW
✓ GZ
✓ XZ

✓ RAW
✓ GZ
✓ XZ

✓ RAW*
□ GZ
□ XZ

✓ RAW*
✓ GZ*
✓ XZ*

Archive+

✓ TAR

✓ TAR

✓ TAR

□ TAR

□ TAR

✓ Supported operation

□ Unsupported operation

* Requires scratch space

** Requires scratch space if a custom certificate authority is required

+ Archive does not support block mode DVs