$ virtctl create vm --name rhel-9-minimal --volume-import type:ds,src:openshift-virtualization-os-images/rhel9
You can create virtual machines (VMs) from the command line by editing or creating a VirtualMachine manifest. You can simplify VM configuration by using an instance type in your VM manifest.
|
You can also create VMs from instance types by using the OKD web console. |
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.
You have installed the virtctl CLI.
You have installed the OpenShift CLI (oc).
Create a VirtualMachine manifest for your VM and save it as a YAML file. For example, to create a minimal Fedora VM, run the following command:
$ virtctl create vm --name rhel-9-minimal --volume-import type:ds,src:openshift-virtualization-os-images/rhel9
Review the VirtualMachine manifest for your VM:
|
This example manifest does not configure VM authentication. |
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: rhel-9-minimal (1)
spec:
dataVolumeTemplates:
- metadata:
name: imported-volume-mk4lj
spec:
sourceRef:
kind: DataSource
name: rhel9 (2)
namespace: openshift-virtualization-os-images (3)
storage:
resources: {}
instancetype:
inferFromVolume: imported-volume-mk4lj (4)
inferFromVolumeFailurePolicy: Ignore
preference:
inferFromVolume: imported-volume-mk4lj (5)
inferFromVolumeFailurePolicy: Ignore
runStrategy: Always
template:
spec:
domain:
devices: {}
memory:
guest: 512Mi
resources: {}
terminationGracePeriodSeconds: 180
volumes:
- dataVolume:
name: imported-volume-mk4lj
name: imported-volume-mk4lj
| 1 | The VM name. |
| 2 | The boot source for the guest operating system. |
| 3 | The namespace for the boot source. Golden images are stored in the openshift-virtualization-os-images namespace. |
| 4 | The instance type is inferred from the selected DataSource object. |
| 5 | The preference is inferred from the selected DataSource object. |
Create a virtual machine by using the manifest file:
$ oc create -f <vm_manifest_file>.yaml
Optional: Start the virtual machine:
$ virtctl start <vm_name>
You can upload an operating system image by using the virtctl command-line tool. You can use an existing data volume or create a new data volume for the image.
You must have an ISO, IMG, or QCOW2 operating system image file.
For best performance, compress the image file by using the virt-sparsify tool or the xz or gzip utilities.
The client machine must be configured to trust the OKD router’s certificate.
You have installed the virtctl CLI.
You have installed the OpenShift CLI (oc).
Upload the image by running the virtctl image-upload command:
$ virtctl image-upload dv <datavolume_name> \
--size=<datavolume_size> \
--image-path=</path/to/image>
<datavolume_name>The name of the data volume.
<datavolume_size>The size of the data volume. For example: --size=500Mi, --size=1G
</path/to/image>The file path of the image.
|
Optional. To verify that a data volume was created, view all data volumes by running the following command:
$ oc get dvs