Skip to content

Commit 4487bdb

Browse files
authored
Merge pull request #89618 from jhradilek/CNV-39983-add-virtctl-commands
CNV-39983: Add "virtctl create vm" to the instructions
2 parents 6a2792a + a8a7cc5 commit 4487bdb

8 files changed

+304
-203
lines changed

modules/virt-creating-vm-cli.adoc

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
// Module included in the following assemblies:
22
//
3-
// * virt/virtual_machines/creating_vms_rh/virt-creating-vms-from-cli.adoc
3+
// * virt/creating_vms_advanced/creating_vms_cli/virt-creating-vms-from-cli.adoc
44

55
:_mod-docs-content-type: PROCEDURE
66
[id="virt-creating-vm-cli_{context}"]
77
= Creating a VM from a VirtualMachine manifest
88

9-
You can create a virtual machine (VM) from a `VirtualMachine` manifest.
9+
You can create a virtual machine (VM) from a `VirtualMachine` manifest. To simplify the creation of these manifests, you can use the `virtctl` command-line tool.
10+
11+
.Prerequisites
12+
13+
* You must have the `virtctl` command-line tool installed.
1014
1115
.Procedure
1216

13-
. Edit the `VirtualMachine` manifest for your VM. The following example configures a {op-system-base-full} VM:
17+
. 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, run the following command:
18+
+
19+
[source,terminal]
20+
----
21+
$ virtctl create vm --name rhel-9-minimal --volume-import type:ds,src:openshift-virtualization-os-images/rhel9
22+
----
23+
24+
. Review the `VirtualMachine` manifest for your VM:
1425
+
1526
[NOTE]
1627
====
@@ -20,38 +31,46 @@ This example manifest does not configure VM authentication.
2031
.Example manifest for a {op-system-base} VM
2132
[source,yaml]
2233
----
23-
apiVersion: kubevirt.io/v1
24-
kind: VirtualMachine
25-
metadata:
26-
name: rhel-9-minimal
27-
spec:
34+
apiVersion: kubevirt.io/v1
35+
kind: VirtualMachine
36+
metadata:
37+
name: rhel-9-minimal # <1>
38+
spec:
2839
dataVolumeTemplates:
29-
- metadata:
30-
name: rhel-9-minimal-volume
31-
spec:
32-
sourceRef:
33-
kind: DataSource
34-
name: rhel9 <1>
35-
namespace: openshift-virtualization-os-images <2>
36-
storage: {}
40+
- metadata:
41+
name: imported-volume-mk4lj
42+
spec:
43+
sourceRef:
44+
kind: DataSource
45+
name: rhel9 # <2>
46+
namespace: openshift-virtualization-os-images # <3>
47+
storage:
48+
resources: {}
3749
instancetype:
38-
name: u1.medium <3>
50+
inferFromVolume: imported-volume-mk4lj # <4>
51+
inferFromVolumeFailurePolicy: Ignore
3952
preference:
40-
name: rhel.9 <4>
53+
inferFromVolume: imported-volume-mk4lj # <5>
54+
inferFromVolumeFailurePolicy: Ignore
4155
runStrategy: Always
4256
template:
4357
spec:
4458
domain:
4559
devices: {}
60+
memory:
61+
guest: 512Mi
62+
resources: {}
63+
terminationGracePeriodSeconds: 180
4664
volumes:
47-
- dataVolume:
48-
name: rhel-9-minimal-volume
49-
name: rootdisk
65+
- dataVolume:
66+
name: imported-volume-mk4lj
67+
name: imported-volume-mk4lj
5068
----
51-
<1> The `rhel9` golden image is used to install {op-system-base} 9 as the guest operating system.
52-
<2> Golden images are stored in the `openshift-virtualization-os-images` namespace.
53-
<3> The `u1.medium` instance type requests 1 vCPU and 4Gi memory for the VM. These resource values cannot be overridden within the VM.
54-
<4> The `rhel.9` preference specifies additional attributes that support the {op-system-base} 9 guest operating system.
69+
<1> The VM name.
70+
<2> The boot source for the guest operating system.
71+
<3> The namespace for the boot source. Golden images are stored in the `openshift-virtualization-os-images` namespace.
72+
<4> The instance type is inferred from the selected `DataSource` object.
73+
<5> The preference is inferred from the selected `DataSource` object.
5574

5675
. Create a virtual machine by using the manifest file:
5776
+
@@ -64,5 +83,5 @@ $ oc create -f <vm_manifest_file>.yaml
6483
+
6584
[source,terminal]
6685
----
67-
$ virtctl start <vm_name> -n <namespace>
86+
$ virtctl start <vm_name>
6887
----
Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,75 @@
11
// Module included in the following assemblies:
22
//
3-
// * virt/virtual_machines/creating_vms_custom/virt-creating-vms-by-cloning-pvcs.adoc
3+
// * virt/creating_vms_advanced/creating_vms_cli/virt-creating-vms-by-cloning-pvcs.adoc
44

55
:_mod-docs-content-type: PROCEDURE
66
[id="virt-creating-vm-cloning-pvc-data-volume-template_{context}"]
77
= Creating a VM from a cloned PVC by using a data volume template
88

9-
You can create a virtual machine (VM) that clones the persistent volume claim (PVC) of an existing VM by using a data volume template.
10-
11-
This method creates a data volume whose lifecycle is dependent on the original VM. Deleting the original VM deletes the cloned data volume and its associated PVC.
9+
You can create a virtual machine (VM) that clones the persistent volume claim (PVC) of an existing VM by using a data volume template. This method creates a data volume whose lifecycle is independent on the original VM.
1210

1311
.Prerequisites
1412

1513
* The VM with the source PVC must be powered down.
14+
* You must have the `virtctl` command-line tool installed.
1615
1716
.Procedure
1817

19-
. Create a `VirtualMachine` manifest as shown in the following example:
18+
. Create a `VirtualMachine` manifest for your VM and save it as a YAML file, for example:
19+
+
20+
[source,terminal]
21+
----
22+
$ virtctl create vm --name rhel-9-clone --volume-import type:pvc,src:my-project/imported-volume-q5pr9
23+
----
24+
25+
. Review the `VirtualMachine` manifest for your VM:
2026
+
2127
[source,yaml]
2228
----
2329
apiVersion: kubevirt.io/v1
2430
kind: VirtualMachine
2531
metadata:
26-
labels:
27-
kubevirt.io/vm: vm-dv-clone
28-
name: vm-dv-clone <1>
32+
name: rhel-9-clone # <1>
2933
spec:
30-
runStrategy: Halted
31-
template:
32-
metadata:
33-
labels:
34-
kubevirt.io/vm: vm-dv-clone
35-
spec:
36-
domain:
37-
devices:
38-
disks:
39-
- disk:
40-
bus: virtio
41-
name: root-disk
42-
resources:
43-
requests:
44-
memory: 64M
45-
volumes:
46-
- dataVolume:
47-
name: favorite-clone
48-
name: root-disk
4934
dataVolumeTemplates:
5035
- metadata:
51-
name: favorite-clone
36+
name: imported-volume-h4qn8
5237
spec:
53-
storage:
54-
accessModes:
55-
- ReadWriteOnce
56-
resources:
57-
requests:
58-
storage: 2Gi
5938
source:
6039
pvc:
61-
namespace: <source_namespace> <2>
62-
name: "<source_pvc>" <3>
40+
name: imported-volume-q5pr9 # <2>
41+
namespace: my-project # <3>
42+
storage:
43+
resources: {}
44+
instancetype:
45+
inferFromVolume: imported-volume-h4qn8 # <4>
46+
inferFromVolumeFailurePolicy: Ignore
47+
preference:
48+
inferFromVolume: imported-volume-h4qn8 # <5>
49+
inferFromVolumeFailurePolicy: Ignore
50+
runStrategy: Always
51+
template:
52+
spec:
53+
domain:
54+
devices: {}
55+
memory:
56+
guest: 512Mi
57+
resources: {}
58+
terminationGracePeriodSeconds: 180
59+
volumes:
60+
- dataVolume:
61+
name: imported-volume-h4qn8
62+
name: imported-volume-h4qn8
6363
----
64-
<1> Specify the name of the VM.
65-
<2> Specify the namespace of the source PVC.
66-
<3> Specify the name of the source PVC.
64+
<1> The VM name.
65+
<2> The name of the source PVC.
66+
<3> The namespace of the source PVC.
67+
<4> If the PVC source has appropriate labels, the instance type is inferred from the selected `DataSource` object.
68+
<5> If the PVC source has appropriate labels, the preference is inferred from the selected `DataSource` object.
6769

6870
. Create the virtual machine with the PVC-cloned data volume:
6971
+
7072
[source,terminal]
7173
----
72-
$ oc create -f <vm-clone-datavolumetemplate>.yaml
74+
$ oc create -f <vm_manifest_file>.yaml
7375
----
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/creating_vms_advanced/creating_vms_cli/virt-creating-vms-from-container-disks.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="virt-creating-vm-import-cli_{context}"]
7+
= Creating a VM from a container disk by using the command line
8+
9+
You can create a virtual machine (VM) from a container disk by using the command line.
10+
11+
.Prerequisites
12+
13+
* You must have access credentials for the container registry that contains the container disk.
14+
* You must have the `virtctl` command-line tool installed.
15+
16+
.Procedure
17+
18+
. 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 a container disk, run the following command:
19+
+
20+
[source,terminal]
21+
----
22+
$ virtctl create vm --name vm-rhel-9 --instancetype u1.small --preference rhel.9 --volume-containerdisk src:registry.redhat.io/rhel9/rhel-guest-image:9.5
23+
----
24+
25+
. Review the `VirtualMachine` manifest for your VM:
26+
+
27+
[source,yaml]
28+
----
29+
apiVersion: kubevirt.io/v1
30+
kind: VirtualMachine
31+
metadata:
32+
name: vm-rhel-9 # <1>
33+
spec:
34+
instancetype:
35+
name: u1.small # <2>
36+
preference:
37+
name: rhel.9 # <3>
38+
runStrategy: Always
39+
template:
40+
metadata:
41+
creationTimestamp: null
42+
spec:
43+
domain:
44+
devices: {}
45+
resources: {}
46+
terminationGracePeriodSeconds: 180
47+
volumes:
48+
- containerDisk:
49+
image: registry.redhat.io/rhel9/rhel-guest-image:9.5 # <4>
50+
name: vm-rhel-9-containerdisk-0
51+
----
52+
<1> The VM name.
53+
<2> The instance type to use to control resource sizing of the VM.
54+
<3> The preference to use.
55+
<4> The URL of the container disk.
56+
57+
. Create the VM by running the following command:
58+
+
59+
[source,terminal]
60+
----
61+
$ oc create -f <vm_manifest_file>.yaml
62+
----
63+
64+
.Verification
65+
66+
. Monitor the status of the VM:
67+
+
68+
[source,terminal]
69+
----
70+
$ oc get vm <vm_name>
71+
----
72+
+
73+
If the provisioning is successful, the VM status is `Running`:
74+
+
75+
.Example output
76+
[source,terminal]
77+
----
78+
NAME AGE STATUS READY
79+
vm-rhel-9 18s Running True
80+
----
81+
82+
. Verify that provisioning is complete and that the VM has started by accessing its serial console:
83+
+
84+
[source,terminal]
85+
----
86+
$ virtctl console <vm_name>
87+
----
88+
+
89+
If the VM is running and the serial console is accessible, the output looks as follows:
90+
+
91+
.Example output
92+
[source,terminal]
93+
----
94+
Successfully connected to vm-rhel-9 console. The escape sequence is ^]
95+
----

0 commit comments

Comments
 (0)