Skip to main content

Import a virtual machine image using the DataVolume API

You can import a virtual machine (VM) image into your OpenShift Virtualization cluster by using the DataVolume API. A DataVolume automates PVC creation and image data transfer from an external source by using the Containerized Data Importer (CDI).

Supported import sources​

The DataVolume API supports importing VM images from several external sources. The Containerized Data Importer (CDI) detects the image format and converts it as needed.

The following import sources are available:

HTTP or HTTPS
You specify the URL of the image file by using the source.http field. CDI downloads the image directly from the web server. You can optionally supply TLS certificates for custom certificate authorities and credentials for Basic authentication.
Container registry
You specify the image location by using the source.registry field with a docker:// URL prefix. CDI pulls the image from the registry by using standard container image pull mechanisms. You can supply registry credentials in a Secret object if the registry requires authentication.
S3 object storage
You specify the object URL by using the source.s3 field. CDI downloads the image from an S3-compatible storage service. You must supply access credentials in a Secret object.
oVirt (ImageIO)
You specify the connection details by using the source.imageio field. CDI connects to the oVirt ImageIO API to transfer disk images from a Red Hat Virtualization environment.
VMware (VDDK)
You specify the connection details by using the source.vddk field. CDI uses the VMware Virtual Disk Development Kit (VDDK) to transfer disk images from a VMware vSphere environment.

Supported image formats include QCOW2, raw, ISO, and compressed archive files.

Import a VM image from a container registry​

You can import a virtual machine (VM) image from a container registry into a persistent volume claim (PVC) by using the DataVolume API. The Containerized Data Importer (CDI) creates a data volume and an associated PVC to store the imported image.

Prerequisites

  • You have access to the container registry.
  • If the registry is private, registry credentials are stored in a Secret object.
  • You have installed the OpenShift CLI (oc).

Procedure

  1. Create a DataVolume object that specifies the container registry as the source:

    apiVersion: cdi.kubevirt.io/v1beta1
    kind: DataVolume
    metadata:
    name: registry-image-datavolume
    spec:
    source:
    registry:
    url: "docker://registry.example.com/my-vm-image:latest"
    pullMethod: node
    secretRef: <registry_secret>
    certConfigMap: <ca_certs_configmap>
    storage:
    resources:
    requests:
    storage: 20Gi

    where:

    url
    Specifies the container registry URL with the docker:// prefix.
    pullMethod
    Optional: Set to node to use the node container runtime cache and pull secrets. The default value is pod.
    secretRef
    Optional: Specifies the name of a Secret object that stores the registry credentials.
    certConfigMap
    Optional: Specifies the name of a ConfigMap object that stores custom CA certificates for the registry.
  2. Create the data volume by running the following command:

    $ oc create -f <datavolume_manifest>.yaml
  3. Monitor the import progress by running the following command:

    $ oc get dv <datavolume_name>

Verification

  • Confirm that the data volume reaches the Succeeded phase by running the following command:

    $ oc get dv <datavolume_name>

    Example output:

    NAME PHASE PROGRESS
    registry-image-datavolume Succeeded 100.0%
  • Confirm that the PVC is created and bound by running the following command:

    $ oc get pvc

    Example output:

    NAME STATUS VOLUME CAPACITY ACCESS MODES
    registry-image-datavolume Bound pv-name 20Gi RWO

CPU architecture selection for DataVolume imports​

You can target a specific CPU architecture when you import a virtual machine (VM) image from an Open Container Initiative (OCI) image index by setting the platform.architecture field in the DataVolume custom resource (CR).

warning

Specifying CPU architecture for data volume imports is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.

For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.

In heterogeneous clusters where nodes run different CPU architectures, importing the correct image variant is essential. Without specifying the target architecture, the imported image might not match the architecture of the node where the VM is scheduled to run. The platform.architecture field resolves this by selecting the appropriate variant from the image index.

The following CPU architectures are supported:

  • amd64
  • arm64
  • s390x

When you set the platform.architecture field in combination with pullMethod: node, OpenShift Virtualization adds a node selector to the importer pod. This node selector ensures that the importer pod runs on a node with the matching CPU architecture. The node pull method uses the container runtime cache of the node where the importer pod runs, so the pod must run on a node with the correct architecture. Without the node selector, the importer pod might run on a node with a different architecture, resulting in a mismatch between the pulled image and the target platform.

Example DataVolume CR:

apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
name: my-vm-image
spec:
source:
registry:
url: "docker://registry.example.com/my-multi-arch-image:latest"
pullMethod: node
platform:
architecture: arm64
storage:
resources:
requests:
storage: 30Gi

Import a VM image from an HTTP or HTTPS source​

You can import a virtual machine (VM) image from an HTTP or HTTPS source by creating a DataVolume object. The Containerized Data Importer (CDI) controller creates a data volume and an underlying persistent volume claim (PVC), then downloads the image from the specified URL into the PVC.

Prerequisites

  • A VM image is accessible from an HTTP or HTTPS URL.
  • Optional: Custom CA certificates for HTTPS connections are stored in a ConfigMap object.
  • You have installed the OpenShift CLI (oc).

Procedure

  1. Create a DataVolume object that specifies the HTTP or HTTPS source of the VM image:

    apiVersion: cdi.kubevirt.io/v1beta1
    kind: DataVolume
    metadata:
    name: http-image-datavolume
    spec:
    source:
    http:
    url: "https://example.com/images/my-vm-image.qcow2"
    secretRef: <http_secret>
    certConfigMap: <ca_certs_configmap>
    storage:
    resources:
    requests:
    storage: 20Gi

    where:

    url
    Specifies the HTTP or HTTPS URL of the VM image.
    secretRef
    Optional: Specifies the name of a Secret object that stores Basic authentication credentials. The Secret must contain username and password keys.
    certConfigMap
    Optional: Specifies the name of a ConfigMap object that stores custom CA certificates for HTTPS connections.
  2. Create the data volume by running the following command:

    $ oc create -f <datavolume_manifest>.yaml
  3. Monitor the import progress by running the following command:

    $ oc get dv <datavolume_name>

Verification

  • Confirm that the data volume reaches the Succeeded phase by running the following command:

    $ oc get dv <datavolume_name>

    Example output:

    NAME PHASE PROGRESS
    http-image-datavolume Succeeded 100.0%
  • Confirm that the PVC is created and bound by running the following command:

    $ oc get pvc

    Example output:

    NAME STATUS VOLUME CAPACITY ACCESS MODES
    http-image-datavolume Bound pv-name 20Gi RWO

Import a VM image from S3 object storage​

You can import a virtual machine (VM) image from an S3-compatible object storage bucket by using a DataVolume object. The Containerized Data Importer (CDI) pulls the image from the S3 endpoint and populates a persistent volume claim (PVC) that you can use to create a VM.

Prerequisites

  • A VM image is stored in an S3-compatible bucket.
  • You have S3 access credentials (access key ID and secret key) for your S3-compatible storage account.
  • You have installed the OpenShift CLI (oc).

Procedure

  1. Create a Secret object for your S3 access credentials:

    apiVersion: v1
    kind: Secret
    metadata:
    name: s3-secret
    type: Opaque
    stringData:
    accessKeyId: "<access_key>"
    secretKey: "<secret_key>"

    where:

    <access_key>
    Specifies the access key ID for your S3-compatible storage account.
    <secret_key>
    Specifies the secret key for your S3-compatible storage account.
  2. Apply the Secret object:

    $ oc create -f <secret_manifest>.yaml
  3. Create a DataVolume object that specifies the S3 source URL and secret reference:

    apiVersion: cdi.kubevirt.io/v1beta1
    kind: DataVolume
    metadata:
    name: s3-image-datavolume
    spec:
    source:
    s3:
    url: "https://s3.example.com/my-bucket/my-vm-image.qcow2"
    secretRef: s3-secret
    certConfigMap: <ca_certs_configmap>
    storage:
    resources:
    requests:
    storage: 20Gi

    where:

    url
    Specifies the S3 URL of the VM image. For non-AWS S3 services, specify the full endpoint URL.
    secretRef
    Specifies the name of the Secret with the S3 access credentials.
    certConfigMap
    Optional: Specifies the name of a ConfigMap object that stores custom CA certificates for the S3 endpoint. Required only if your endpoint uses a custom certificate authority.
  4. Apply the DataVolume object by running the following command:

    $ oc create -f <datavolume_manifest>.yaml
  5. Monitor the import progress by running the following command:

    $ oc get dv <datavolume_name>

Verification

  • Confirm that the data volume reaches the Succeeded phase by running the following command:

    $ oc get dv <datavolume_name>

    Example output:

    NAME PHASE PROGRESS
    s3-image-datavolume Succeeded 100.0%
  • Confirm that the PVC is created and bound by running the following command:

    $ oc get pvc

    Example output:

    NAME STATUS VOLUME CAPACITY ACCESS MODES
    s3-image-datavolume Bound pv-name 20Gi RWO

DataVolume source fields​

You can configure a DataVolume object to import a virtual machine (VM) image from several source types. Each source type has its own set of fields that control where and how the Containerized Data Importer (CDI) retrieves the image.

Registry source fields​

The source.registry source type imports a VM image from a container registry.

source.registry** fields**

FieldTypeDescription
urlStringContainer registry URL of the image, specified with the docker:// prefix. For example, docker://registry.example.com/my-image:latest.
pullMethodStringMethod for pulling the image. Specify pod to use the CDI importer pod or node to use the node’s container image cache. The default value is pod.
secretRefStringName of a Secret object that stores the credentials for the container registry.
certConfigMapStringName of a ConfigMap object that stores custom certificate authority (CA) certificates for the container registry.
platform.architectureStringTarget CPU architecture when importing from a multi-architecture image index. Supported values are amd64, arm64, and s390x. This field is a Technology Preview feature.

HTTP source fields​

The source.http source type imports a VM image from an HTTP or HTTPS URL.

source.http** fields**

FieldTypeDescription
urlStringHTTP or HTTPS URL of the VM image.
secretRefStringName of a Secret object that stores Basic authentication credentials for the HTTP server.
certConfigMapStringName of a ConfigMap object that stores custom certificate authority (CA) certificates for the HTTP server.
extraHeadersList of stringsAdditional HTTP headers to include in the image download request.
secretExtraHeadersList of stringsNames of Secret objects that store additional HTTP headers to include in the image download request.

S3 source fields​

The source.s3 source type imports a VM image from an S3-compatible object storage bucket.

source.s3** fields**

FieldTypeDescription
urlStringS3 URL of the VM image.
secretRefStringName of a Secret object that stores the S3 access key ID and secret access key.
certConfigMapStringName of a ConfigMap object that stores custom certificate authority (CA) certificates for the S3 endpoint.

ImageIO source fields​

The source.imageio source type imports a disk image from a Red Hat Virtualization (oVirt) environment by using the ImageIO API.

source.imageio** fields**

FieldTypeDescription
urlStringURL of the oVirt Engine API endpoint. For example, https://ovirt-engine.example.com/ovirt-engine/api.
diskIdStringID of the oVirt disk to import.
secretRefStringName of a Secret object that stores the credentials to access the oVirt Engine.
certConfigMapStringName of a ConfigMap object that stores CA certificates for the oVirt Engine.

VDDK source fields​

The source.vddk source type imports a disk image from a VMware vSphere environment by using the Virtual Disk Development Kit (VDDK).

source.vddk** fields**

FieldTypeDescription
urlStringURL of the vCenter or ESXi host.
uuidStringUUID of the virtual machine in vCenter or ESXi.
backingFileStringPath to the virtual hard drive to import from vCenter or ESXi.
thumbprintStringTLS certificate thumbprint of the vCenter or ESXi host.
secretRefStringName of a Secret object that stores the username and password for the vCenter or ESXi host.
initImageURLStringURL of a container image with an extracted VDDK library. Overrides the v2v-vmware config map.

Blank source​

The source.blank source type creates an empty disk with no data. This source type has no configurable fields.

PVC source fields​

The source.pvc source type clones the contents of an existing persistent volume claim (PVC).

source.pvc** fields**

FieldTypeDescription
namespaceStringNamespace of the source PVC.
nameStringName of the source PVC.

VolumeSnapshot source fields​

The source.snapshot source type creates a volume from an existing VolumeSnapshot object.

source.snapshot** fields**

FieldTypeDescription
namespaceStringNamespace of the source VolumeSnapshot object.
nameStringName of the source VolumeSnapshot object.

Supported content types​

The Containerized Data Importer (CDI) supports the following content types for VM image imports:

  • QCOW2
  • Raw
  • ISO
  • Archive (tar.gz)

Troubleshoot data volume imports​

You can diagnose and resolve common issues with data volume imports by inspecting data volume conditions and events. Understanding these conditions helps you identify the root cause of failed or stalled imports.

Data volume conditions​

Each data volume reports three conditions that indicate its current state. You can view these conditions by running the oc describe dv command.

Bound
Indicates whether the persistent volume claim (PVC) has been created and bound to a persistent volume. Status: True means the PVC is bound.
Running
Indicates whether an import operation is actively running. Status: True means data is being imported.
Ready
Indicates whether the data volume is ready to use. Status: True means the import completed successfully.

Diagnostic commands​

You can use the following commands to gather information about a data volume import:

oc describe dv <datavolume_name>
Shows the data volume conditions, events, and status. Replace <datavolume_name> with the name of your data volume.
oc get events --field-selector involvedObject.name=<datavolume_name>
Shows events related to the data volume. Replace <datavolume_name> with the name of your data volume.

Common failure scenarios​

Common data volume import failures

SymptomPossible causeResolution
Import pod in ErrImagePull or ImagePullBackOffWrong registry URL or missing credentialsVerify the registry URL and ensure the secretRef points to a valid Secret.
Import pod in CrashLoopBackOffInvalid image format or corrupted imageVerify the image is in a supported format (QCOW2, raw, ISO, archive).
Data volume stuck in ImportScheduledNo available persistent volume matching the storage requestVerify available storage and storage class configuration.
Data volume shows Scratch space required errorCDI requires scratch space for image conversion but none is availableConfigure a scratch space storage class in the CDI object or ensure enough storage is available.
TLS certificate errorsCustom CA not configuredCreate a ConfigMap object with the CA certificate and reference it in the certConfigMap field.
HTTP 401 or 403 errorsMissing or invalid authentication credentialsVerify the Secret referenced by secretRef has valid credentials.

Additional resources