8.6. Creating virtual machines by using the CLI
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 OpenShift Container Platform web console.
8.6.1. Creating a VM from a VirtualMachine manifest 링크 복사링크가 클립보드에 복사되었습니다!
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.
Prerequisites
-
You have installed the
virtctlCLI. -
You have installed the OpenShift CLI (
oc).
Procedure
Create a
VirtualMachinemanifest for your VM and save it as a YAML file. For example, to create a minimal Red Hat Enterprise Linux (RHEL) VM, run the following command:$ virtctl create vm --name rhel-9-minimal --volume-import type:ds,src:openshift-virtualization-os-images/rhel9Review the
VirtualMachinemanifest for your VM:참고This example manifest does not configure VM authentication.
Example manifest for a RHEL VM
apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: rhel-9-minimal1 spec: dataVolumeTemplates: - metadata: name: imported-volume-mk4lj spec: sourceRef: kind: DataSource name: rhel92 namespace: openshift-virtualization-os-images3 storage: resources: {} instancetype: inferFromVolume: imported-volume-mk4lj4 inferFromVolumeFailurePolicy: Ignore preference: inferFromVolume: imported-volume-mk4lj5 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-imagesnamespace. - 4
- The instance type is inferred from the selected
DataSourceobject. - 5
- The preference is inferred from the selected
DataSourceobject.
Create a virtual machine by using the manifest file:
$ oc create -f <vm_manifest_file>.yamlOptional: Start the virtual machine:
$ virtctl start <vm_name>