Creating VMs by importing images from web pages

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 Customize VirtualMachine.

  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. If the web page requires authentication, create a Secret manifest, specifying the credentials, and save it as a data-source-secret.yaml file:

    1. apiVersion: v1
    2. kind: Secret
    3. metadata:
    4. name: data-source-secret
    5. labels:
    6. app: containerized-data-importer
    7. type: Opaque
    8. data:
    9. accessKeyId: "" (1)
    10. secretKey: "" (2)
    1Specify the Base64-encoded key ID or user name.
    2Specify the Base64-encoded secret key or password.
  2. Apply the Secret manifest by running the following command:

    1. $ oc apply -f data-source-secret.yaml
  3. If the VM must communicate with servers that use self-signed certificates or certificates that are not signed by the system CA bundle, create a config map in the same namespace as the VM:

    1. $ oc create configmap tls-certs (1)
    2. --from-file=</path/to/file/ca.pem> (2)
    1Specify the config map name.
    2Specify the path to the CA certificate.
  4. Edit the VirtualMachine manifest and save it as a vm-fedora-datavolume.yaml file:

    Details

    1. apiVersion: kubevirt.io/v1
    2. kind: VirtualMachine
    3. metadata:
    4. creationTimestamp: null
    5. labels:
    6. kubevirt.io/vm: vm-fedora-datavolume
    7. name: vm-fedora-datavolume (1)
    8. spec:
    9. dataVolumeTemplates:
    10. - metadata:
    11. creationTimestamp: null
    12. name: fedora-dv (2)
    13. spec:
    14. storage:
    15. resources:
    16. requests:
    17. storage: 10Gi (3)
    18. storageClassName: <storage_class> (4)
    19. source:
    20. http:
    21. url: "https://mirror.arizona.edu/fedora/linux/releases/35/Cloud/x86_64/images/Fedora-Cloud-Base-35-1.2.x86_64.qcow2" (5)
    22. secretRef: data-source-secret (6)
    23. certConfigMap: tls-certs (7)
    24. status: {}
    25. running: true
    26. template:
    27. metadata:
    28. creationTimestamp: null
    29. labels:
    30. kubevirt.io/vm: vm-fedora-datavolume
    31. spec:
    32. domain:
    33. devices:
    34. disks:
    35. - disk:
    36. bus: virtio
    37. name: datavolumedisk1
    38. machine:
    39. type: ""
    40. resources:
    41. requests:
    42. memory: 1.5Gi
    43. terminationGracePeriodSeconds: 180
    44. volumes:
    45. - dataVolume:
    46. name: fedora-dv
    47. name: datavolumedisk1
    48. status: {}
    1Specify the name of the VM.
    2Specify the name of the data volume.
    3Specify the size of the storage requested for the data volume.
    4Optional: If you do not specify a storage class, the default storage class is used.
    5Specify the URL of the web page.
    6Optional: Specify the secret name if you created a secret for the web page access credentials.
    7Optional: Specify a CA certificate config map.
  5. Create the VM by running the following command:

    1. $ oc create -f vm-fedora-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:

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

    1. $ oc describe dv fedora-dv (1)
    1Specify 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:

    1. $ virtctl console vm-fedora-datavolume