×

You can create virtual machines (VMs) by importing operating system images from web pages.

You must install the QEMU guest agent on VMs created from operating system images that are not provided by Red Hat.

Creating a VM from an image on a web page by using the web console

You can create a virtual machine (VM) by importing an image from a web page by using the OKD web console.

Prerequisites
  • You must have access to the web page that contains the image.

Procedure
  1. Navigate to VirtualizationCatalog in the web console.

  2. Click a template tile without an available boot source.

  3. Click Customize VirtualMachine.

  4. On the Customize template parameters page, expand Storage and select URL (creates PVC) from the Disk source list.

  5. Enter the image URL. Example: https://access.redhat.com/downloads/content/69/ver=/rhel---7/7.9/x86_64/product-software

  6. Set the disk size.

  7. Click Next.

  8. Click Create VirtualMachine.

Creating a VM from an image on a web page by using the command line

You can create a virtual machine (VM) from an image on a web page by using the command line.

When the virtual machine (VM) is created, the data volume with the image is imported into persistent storage.

Prerequisites
  • You must have access credentials for the web page that contains the image.

Procedure
  1. Edit the VirtualMachine manifest and save it as a vm-rhel-datavolume.yaml file:

    Details
    apiVersion: kubevirt.io/v1
    kind: VirtualMachine
    metadata:
      creationTimestamp: null
      name: vm-rhel-datavolume (1)
      labels:
        kubevirt.io/vm: vm-rhel-datavolume
    spec:
      dataVolumeTemplates:
      - metadata:
          creationTimestamp: null
          name: rhel-dv (2)
        spec:
          sourceRef:
            kind: DataSource
            name: rhel9
            namespace: openshift-virtualization-os-images
          storage:
            resources:
              requests:
                storage: 10Gi (3)
      instancetype:
        name: u1.small (4)
      preference:
        inferFromVolume: datavolumedisk1
      runStrategy: Always
      template:
        metadata:
          creationTimestamp: null
          labels:
            kubevirt.io/vm: vm-rhel-datavolume
        spec:
          domain:
            devices: {}
            resources: {}
          terminationGracePeriodSeconds: 180
          volumes:
          - dataVolume:
              name: rhel-dv
            name: datavolumedisk1
    status: {}
    1 Specify the name of the VM.
    2 Specify the name of the data volume.
    3 Specify the size of the storage requested for the data volume.
    4 Optional: Specify the instance type to use to control resource sizing of the VM.
  2. Create the VM by running the following command:

    $ oc create -f vm-rhel-datavolume.yaml

    The oc create command creates the data volume and the VM. The CDI controller creates an underlying PVC with the correct annotation and the import process begins. When the import is complete, the data volume status changes to Succeeded. You can start the VM.

    Data volume provisioning happens in the background, so there is no need to monitor the process.

Verification
  1. The importer pod downloads the image from the specified URL and stores it on the provisioned persistent volume. View the status of the importer pod by running the following command:

    $ oc get pods
  2. Monitor the data volume until its status is Succeeded by running the following command:

    $ oc describe dv rhel-dv (1)
    1 Specify the data volume name that you defined in the VirtualMachine manifest.
  3. Verify that provisioning is complete and that the VM has started by accessing its serial console:

    $ virtctl console vm-rhel-datavolume