mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
Brand new YAML for VM creation Kudos to fmatouschek for the support Removed outdated steps as per SME input Applying QE review Kudos to Roni Kirshner for the feedback
129 lines
3.5 KiB
Plaintext
129 lines
3.5 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * virt/virtual_machines/creating_vms_custom/virt-creating-vms-from-container-disks.adoc
|
|
// * virt/virtual_machines/creating_vms_custom/virt-creating-vms-from-web-images.adoc
|
|
|
|
ifeval::["{context}" == "virt-creating-vms-from-web-images"]
|
|
:url:
|
|
:title-frag: from an image on a web page
|
|
:a-object: an image
|
|
:object: image
|
|
:data-source: web page
|
|
endif::[]
|
|
ifeval::["{context}" == "virt-creating-vms-from-container-disks"]
|
|
:container-disks:
|
|
:title-frag: from a container disk
|
|
:a-object: a container disk
|
|
:object: container disk
|
|
:data-source: container registry
|
|
endif::[]
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
[id="virt-creating-vm-import-cli_{context}"]
|
|
= Creating a VM {title-frag} by using the command line
|
|
|
|
You can create a virtual machine (VM) {title-frag} by using the command line.
|
|
|
|
When the virtual machine (VM) is created, the data volume with the {object} is imported into persistent storage.
|
|
|
|
.Prerequisites
|
|
|
|
* You must have access credentials for the {data-source} that contains the {object}.
|
|
|
|
.Procedure
|
|
|
|
. Edit the `VirtualMachine` manifest and save it as a `vm-rhel-datavolume.yaml` file:
|
|
+
|
|
[%collapsible]
|
|
====
|
|
[source,yaml]
|
|
----
|
|
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.
|
|
====
|
|
|
|
. Create the VM by running the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ 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
|
|
|
|
. The importer pod downloads the {object} from the specified URL and stores it on the provisioned persistent volume. View the status of the importer pod by running the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc get pods
|
|
----
|
|
|
|
. Monitor the data volume until its status is `Succeeded` by running the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc describe dv rhel-dv <1>
|
|
----
|
|
<1> Specify the data volume name that you defined in the `VirtualMachine` manifest.
|
|
|
|
. Verify that provisioning is complete and that the VM has started by accessing its serial console:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ virtctl console vm-rhel-datavolume
|
|
----
|
|
|
|
ifeval::["{context}" == "creating-vms-from-web-images"]
|
|
:!url:
|
|
endif::[]
|
|
ifeval::["{context}" == "creating-vms-from-container-disks"]
|
|
:!container-disks:
|
|
endif::[] |