1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/virt-creating-vm-web-page-cli.adoc
Shauna Diaz b18daad371 Merge pull request #93591 from jhradilek/add-oc-prerequisite
Add the "oc" utility to prerequisites
2025-05-21 14:35:11 -04:00

121 lines
3.3 KiB
Plaintext

// Module included in the following assemblies:
//
// * virt/creating_vms_advanced/creating_vms_advanced_web/virt-creating-vms-from-web-images.adoc
:_mod-docs-content-type: PROCEDURE
[id="virt-creating-vm-import-cli_{context}"]
= Creating a VM from an image on a web page by using the CLI
You can create a virtual machine (VM) from an image on a web page by using the command line.
When the 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.
* You have installed the `virtctl` CLI.
* You have installed the {oc-first}.
.Procedure
. Create a `VirtualMachine` manifest for your VM and save it as a YAML file. For example, to create a minimal {op-system-base-full} VM from an image on a web page, run the following command:
+
[source,terminal]
----
$ virtctl create vm --name vm-rhel-9 --instancetype u1.small --preference rhel.9 --volume-import type:http,url:https://example.com/rhel9.qcow2,size:10Gi
----
. Review the `VirtualMachine` manifest for your VM:
+
[source,yaml]
----
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: vm-rhel-9 # <1>
spec:
dataVolumeTemplates:
- metadata:
name: imported-volume-6dcpf # <2>
spec:
source:
http:
url: https://example.com/rhel9.qcow2 # <3>
storage:
resources:
requests:
storage: 10Gi # <4>
instancetype:
name: u1.small # <5>
preference:
name: rhel.9 # <6>
runStrategy: Always
template:
spec:
domain:
devices: {}
resources: {}
terminationGracePeriodSeconds: 180
volumes:
- dataVolume:
name: imported-volume-6dcpf
name: imported-volume-6dcpf
----
<1> The VM name.
<2> The data volume name.
<3> The URL of the image.
<4> The size of the storage requested for the data volume.
<5> The instance type to use to control resource sizing of the VM.
<6> The preference to use.
. Create the VM by running the following command:
+
[source,terminal]
----
$ oc create -f <vm_manifest_file>.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
. 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:
+
[source,terminal]
----
$ oc get pods
----
. Monitor the status of the data volume:
+
[source,terminal]
----
$ oc get dv <data_volume_name>
----
+
If the provisioning is successful, the data volume phase is `Succeeded`:
+
.Example output
[source,terminal]
----
NAME PHASE PROGRESS RESTARTS AGE
imported-volume-6dcpf Succeeded 100.0% 18s
----
. Verify that provisioning is complete and that the VM has started by accessing its serial console:
+
[source,terminal]
----
$ virtctl console <vm_name>
----
+
If the VM is running and the serial console is accessible, the output looks as follows:
+
.Example output
[source,terminal]
----
Successfully connected to vm-rhel-9 console. The escape sequence is ^]
----