Creating Virtual Machines
Create a virtual machine (a VirtualMachine resource) using an image, and schedule it to physical nodes with KubeVirt components installed and virtualization enabled. A VirtualMachine is the desired-state object (analogous to a Deployment); when it is started, KubeVirt produces a running VirtualMachineInstance (analogous to a Pod). For the terms used on this page, see Concepts and Glossary.
You can create a virtual machine through Create Virtual Machine using a form, and you may also switch to YAML format for the operation.
Size new virtual machines with an instance type and a preference. An instance type declares the CPU and memory once and is shared by every virtual machine that references it; a preference applies the device and firmware settings the guest operating system works best with. Setting CPU and memory directly in the virtual machine (a machine model) remains available as an alternative. See Instance Types and Preferences.
TOC
PrerequisitesNotesCreate Virtual MachineProcedureRelated OperationsUsing the APIRecommended: Reference an Instance Type and a PreferenceFollow the ImageAlternative: Set the Size in the Virtual Machine (Machine Model)Prerequisites
-
Before creating a virtual machine using an image, please confirm the following with the platform administrator:
-
The target cluster is a workload cluster that the platform creates on a non-Alauda OS, and the Kubevirt components have been deployed.
-
The target node must be a physical node with virtualization enabled.
-
An image source has been added to the platform and assigned to the project, or an image instance is available in
kube-publicor in the namespace (see Images).
-
-
If you need to use the physical GPU passthrough feature of the virtual machine, please contact the platform administrator for the following configuration:
-
Obtain GPU passthrough environment preparation plan and prepare the necessary environment.
-
Prepare the required physical GPU and enable the related features for physical GPU passthrough for the virtual machine.
-
Notes
When using Windows virtual machines, only logins via the username/password set in the virtual machine image are supported. Please contact the platform administrator to obtain this information in advance.
Create Virtual Machine
Procedure
Note: The following content presents an example of creating a virtual machine using a form, and you may also switch to YAML format for the operation.
-
Enter Container Platform.
-
In the left navigation bar, click Virtualization > Virtual Machines.
-
Click Create Virtual Machine.
-
In the Basic Information area, fill in the name and display name of the virtual machine and set tags or annotations.
-
In the Image area, choose the image the virtual machine boots from.
-
In the Model area, choose how the virtual machine is sized.
-
In the Storage area, refer to the following instructions to configure the relevant information.
-
In the Network area, refer to the following instructions to configure the relevant information.
-
In the Initialization Settings area, refer to the following instructions to configure the relevant information.
-
(Optional) In the Advanced Configuration area, refer to the following instructions to configure the relevant information.
-
After confirming that the information is correct, click Create.
Wait for the virtual machine to change from Creating to Running status.
Related Operations
You can click the ⋮ icon on the right side of the list page or the Actions in the upper right corner of the details page to update or delete the virtual machine as needed. For other related operations like resetting passwords or updating keys, please refer to Manage Virtual Machines.
Note:
-
Updates can only be performed when the virtual machine is in Abnormal, Unknown, or Stopped status.
-
Updates do not support displaying disks that were separately attached or created after the virtual machine was created.
-
By default, Start Immediately is disabled during updates; you can enable it as needed.
Using the API
A virtual machine is a VirtualMachine (kubevirt.io/v1).
Recommended: Reference an Instance Type and a Preference
The virtual machine below boots from a bootable volume (a DataSource), takes its size from the cluster instance type u1.medium and its device settings from the cluster preference centos.stream9, attaches a pod network, and injects an SSH key through cloud-init:
- To reference a namespaced object, set
kindtoVirtualMachineInstancetypeorVirtualMachinePreference; the object must be in the namespace of the virtual machine. A reference withoutkindmeans the cluster-scoped kind. - A virtual machine that references an instance type must not set
spec.template.spec.domain.resourcesCPU or memory,domain.cpu.sockets/cores/threads,domain.memory.guest, or any other setting the instance type sets; such a virtual machine is rejected. - The preference only fills settings the virtual machine leaves unset: a disk with an explicit
bus, for example, keeps its bus.
Follow the Image
When the bootable volume declares a default instance type and preference (see Bootable Volumes), the virtual machine can take them from the volume instead of naming the objects. This is what Follow the image writes:
The platform reads the default from the volume once, when the virtual machine is created, and stores the object it names in the virtual machine — spec.instancetype.name and spec.preference.name replace the inferFromVolume fields. Changing the labels of the volume later does not change existing virtual machines. With the policy Reject, creation is refused if the volume declares no default; with Ignore, the virtual machine is created without that instance type or preference.
Alternative: Set the Size in the Virtual Machine (Machine Model)
Without an instance type, the size is written into the template. ACP uses a resource-limit model, so requests and limits carry the same values. A preference can still be referenced:
The boot disk is provisioned by the dataVolumeTemplates entry, which clones the referenced bootable volume. To change the size of a virtual machine later, or to move a virtual machine from a machine model to an instance type, see Managing Virtual Machines.