- Creating virtual machines
- Using a Quick Start to create a virtual machine
- Running the virtual machine wizard to create a virtual machine
- Pasting in a pre-configured YAML file to create a virtual machine
- Using the CLI to create a virtual machine
- Virtual machine storage volume types
- About RunStrategies for virtual machines
- Additional resources
Creating virtual machines
Use one of these procedures to create a virtual machine:
Quick Start guided tour
Running the wizard
Pasting a pre-configured YAML file with the virtual machine wizard
Using the CLI
Do not create virtual machines in |
When you create virtual machines from the web console, select a virtual machine template that is configured with a boot source. Virtual machine templates with a boot source are labeled as Available boot source or they display a customized label text. Using templates with an available boot source expedites the process of creating virtual machines.
Templates without a boot source are labeled as Boot source required. You can use these templates if you complete the steps for adding a boot source to the virtual machine.
Due to differences in storage behavior, some virtual machine templates are incompatible with SNO. To ensure compatibility, do not set the |
Using a Quick Start to create a virtual machine
The web console provides Quick Starts with instructional guided tours for creating virtual machines. You can access the Quick Starts catalog by selecting the Help menu in the Administrator perspective to view the Quick Starts catalog. When you click on a Quick Start tile and begin the tour, the system guides you through the process.
Tasks in a Quick Start begin with selecting a Red Hat template. Then, you can add a boot source and import the operating system image. Finally, you can save the custom template and use it to create a virtual machine.
Quick Start tours for creating virtual machines include the following:
Creating a Red Hat Enterprise Linux virtual machine
Creating a Windows 10 virtual machine
Importing a VMWare virtual machine
Prerequisites
- Access to the website where you can download the URL link for the operating system image.
Procedure
In the web console, select Quick Starts from the Help menu.
Click on a tile in the Quick Starts catalog. For example: Creating a Red Hat Linux Enterprise Linux virtual machine.
Follow the instructions in the guided tour and complete the tasks for importing an operating system image and creating a virtual machine. The Virtual Machines tab displays the virtual machine.
Running the virtual machine wizard to create a virtual machine
The web console features a wizard that guides you through the process of selecting a virtual machine template and creating a virtual machine. Red Hat virtual machine templates are preconfigured with an operating system image, default settings for the operating system, flavor (CPU and memory), and workload type (server). When templates are configured with a boot source, they are labeled with a customized label text or the default label text Available boot source. These templates are then ready to be used for creating virtual machines.
You can select a template from the list of preconfigured templates, review the settings, and create a virtual machine in the Create virtual machine from template wizard. If you choose to customize your virtual machine, the wizard guides you through the General, Networking, Storage, Advanced, and Review steps. All required fields displayed by the wizard are marked by a *.
Create network interface controllers (NICs) and storage disks later and attach them to virtual machines.
Procedure
Click Workloads → Virtualization from the side menu.
From the Virtual Machines tab or the Templates tab, click Create and select Virtual Machine with Wizard.
Select a template that is configured with a boot source.
Click Next to go to the Review and create step.
Clear the Start this virtual machine after creation checkbox if you do not want to start the virtual machine now.
Click Create virtual machine and exit the wizard or continue with the wizard to customize the virtual machine.
Click Customize virtual machine to go to the General step.
Optional: Edit the Name field to specify a custom name for the virtual machine.
Optional: In the Description field, add a description.
Click Next to go to the Networking step. A
nic0
NIC is attached by default.Optional: Click Add Network Interface to create additional NICs.
Optional: You can remove any or all NICs by clicking the Options menu and selecting Delete. A virtual machine does not need a NIC attached to be created. You can create NICs after the virtual machine has been created.
Click Next to go to the Storage step.
Optional: Click Add Disk to create additional disks. These disks can be removed by clicking the Options menu and selecting Delete.
Optional: Click the Options menu to edit the disk and save your changes.
Click Next to go to the Advanced step and choose one of the following options:
If you selected a Linux template to create the VM, review the details for Cloud-init and configure SSH access.
Statically inject an SSH key by using the custom script in cloud-init or in the wizard. This allows you to securely and remotely manage virtual machines and manage and transfer information. This step is strongly recommended to secure your VM.
If you selected a Windows template to create the VM, use the SysPrep section to upload answer files in XML format for automated Windows setup.
Click Next to go to the Review step and review the settings for the virtual machine.
Click Create Virtual Machine.
Click See virtual machine details to view the Overview for this virtual machine.
The virtual machine is listed in the Virtual Machines tab.
Refer to the virtual machine wizard fields section when running the web console wizard.
Virtual machine wizard fields
Name | Parameter | Description | ||
---|---|---|---|---|
Name | The name can contain lowercase letters ( | |||
Description | Optional description field. | |||
Operating System | The operating system that is selected for the virtual machine in the template. You cannot edit this field when creating a virtual machine from a template. | |||
Boot Source | Import via URL (creates PVC) | Import content from an image available from an HTTP or S3 endpoint. Example: Obtaining a URL link from the web page with the operating system image. | ||
Clone existing PVC (creates PVC) | Select an existent persistent volume claim available on the cluster and clone it. | |||
Import via Registry (creates PVC) | Provision virtual machine from a bootable operating system container located in a registry accessible from the cluster. Example: | |||
PXE (network boot - adds network interface) | Boot an operating system from a server on the network. Requires a PXE bootable network attachment definition. | |||
Persistent Volume Claim project | Project name that you want to use for cloning the PVC. | |||
Persistent Volume Claim name | PVC name that should apply to this virtual machine template if you are cloning an existing PVC. | |||
Mount this as a CD-ROM boot source | A CD-ROM requires an additional disk for installing the operating system. Select the checkbox to add a disk and customize it later. | |||
Flavor | Tiny, Small, Medium, Large, Custom | Presets the amount of CPU and memory in a virtual machine template with predefined values that are allocated to the virtual machine, depending on the operating system associated with that template. If you choose a default template, you can override the | ||
Workload Type
| Desktop | A virtual machine configuration for use on a desktop. Ideal for consumption on a small scale. Recommended for use with the web console. Use this template class or the Server template class to prioritize VM density over | ||
Server | Balances performance and it is compatible with a wide range of server workloads. Use this template class or the Desktop template class to prioritize VM density over | |||
High-Performance (requires CPU Manager) | A virtual machine configuration that is optimized for high-performance workloads. Use this template class to prioritize | |||
Start this virtual machine after creation. | This checkbox is selected by default and the virtual machine starts running after creation. Clear the checkbox if you do not want the virtual machine to start when it is created. |
Enable the CPU Manager to use the high-performance workload profile.
Networking fields
Name | Description |
---|---|
Name | Name for the network interface controller. |
Model | Indicates the model of the network interface controller. Supported values are e1000e and virtio. |
Network | List of available network attachment definitions. |
Type | List of available binding methods. For the default pod network, |
MAC Address | MAC address for the network interface controller. If a MAC address is not specified, one is assigned automatically. |
Storage fields
Name | Selection | Description | ||
---|---|---|---|---|
Source | Blank (creates PVC) | Create an empty disk. | ||
Import via URL (creates PVC) | Import content via URL (HTTP or S3 endpoint). | |||
Use an existing PVC | Use a PVC that is already available in the cluster. | |||
Clone existing PVC (creates PVC) | Select an existing PVC available in the cluster and clone it. | |||
Import via Registry (creates PVC) | Import content via container registry. | |||
Container (ephemeral) | Upload content from a container located in a registry accessible from the cluster. The container disk should be used only for read-only filesystems such as CD-ROMs or temporary virtual machines. | |||
Name | Name of the disk. The name can contain lowercase letters ( | |||
Size | Size of the disk in GiB. | |||
Type | Type of disk. Example: Disk or CD-ROM | |||
Interface | Type of disk device. Supported interfaces are virtIO, SATA, and SCSI. | |||
Storage Class | The storage class that is used to create the disk. | |||
Advanced → Volume Mode
| Defines whether the persistent volume uses a formatted file system or raw block state. Default is Filesystem. |
Advanced storage settings
Name | Parameter | Description | ||
---|---|---|---|---|
Volume Mode
| Filesystem | Stores the virtual disk on a file system-based volume. | ||
Block | Stores the virtual disk directly on the block volume. Only use |
Cloud-init fields
Name | Description |
---|---|
Hostname | Sets a specific hostname for the virtual machine. |
Authorized SSH Keys | The user’s public key that is copied to ~/.ssh/authorized_keys on the virtual machine. |
Custom script | Replaces other options with a field in which you paste a custom cloud-init script. |
To configure storage class defaults, use storage profiles. For more information, see Customizing the storage profile.
Pasting in a pre-configured YAML file to create a virtual machine
Create a virtual machine by writing or pasting a YAML configuration file. A valid example
virtual machine configuration is provided by default whenever you open the YAML edit screen.
If your YAML configuration is invalid when you click Create, an error message indicates the parameter in which the error occurs. Only one error is shown at a time.
Navigating away from the YAML screen while editing cancels any changes to the configuration you have made. |
Procedure
Click Workloads → Virtualization from the side menu.
Click the Virtual Machines tab.
Click Create and select Virtual Machine With YAML.
Write or paste your virtual machine configuration in the editable window.
- Alternatively, use the
example
virtual machine provided by default in the YAML screen.
- Alternatively, use the
Optional: Click Download to download the YAML configuration file in its present state.
Click Create to create the virtual machine.
The virtual machine is listed in the Virtual Machines tab.
Using the CLI to create a virtual machine
Procedure
The spec
object of the virtual machine configuration file references the virtual machine settings, such as the number of cores and the amount of memory, the disk type, and the volumes to use.
Attach the virtual machine disk to the virtual machine by referencing the relevant PVC
claimName
as a volume.To create a virtual machine with the OKD client, run this command:
$ oc create -f <vm.yaml>
Since virtual machines are created in a Stopped state, run a virtual machine instance by starting it.
A ReplicaSet‘s purpose is often used to guarantee the availability of a specified number of identical pods. ReplicaSet is not currently supported in OKD Virtualization. |
Setting | Description |
---|---|
Cores | The number of cores inside the virtual machine. Must be a value greater than or equal to 1. |
Memory | The amount of RAM that is allocated to the virtual machine by the node. Specify a value in M for Megabyte or Gi for Gigabyte. |
Disks | The name of the volume that is referenced. Must match the name of a volume. |
Setting | Description |
---|---|
Name | The name of the volume, which must be a DNS label and unique within the virtual machine. |
PersistentVolumeClaim | The PVC to attach to the virtual machine. The |
Virtual machine storage volume types
Storage volume type | Description | ||
---|---|---|---|
ephemeral | A local copy-on-write (COW) image that uses a network volume as a read-only backing store. The backing volume must be a PersistentVolumeClaim. The ephemeral image is created when the virtual machine starts and stores all writes locally. The ephemeral image is discarded when the virtual machine is stopped, restarted, or deleted. The backing volume (PVC) is not mutated in any way. | ||
persistentVolumeClaim | Attaches an available PV to a virtual machine. Attaching a PV allows for the virtual machine data to persist between sessions. Importing an existing virtual machine disk into a PVC by using CDI and attaching the PVC to a virtual machine instance is the recommended method for importing existing virtual machines into OKD. There are some requirements for the disk to be used within a PVC. | ||
dataVolume | Data volumes build on the Specify | ||
cloudInitNoCloud | Attaches a disk that contains the referenced cloud-init NoCloud data source, providing user data and metadata to the virtual machine. A cloud-init installation is required inside the virtual machine disk. | ||
containerDisk | References an image, such as a virtual machine disk, that is stored in the container image registry. The image is pulled from the registry and attached to the virtual machine as a disk when the virtual machine is launched. A Only RAW and QCOW2 formats are supported disk types for the container image registry. QCOW2 is recommended for reduced image size.
| ||
emptyDisk | Creates an additional sparse QCOW2 disk that is tied to the life-cycle of the virtual machine interface. The data survives guest-initiated reboots in the virtual machine but is discarded when the virtual machine stops or is restarted from the web console. The empty disk is used to store application dependencies and data that otherwise exceeds the limited temporary file system of an ephemeral disk. The disk capacity size must also be provided. |
About RunStrategies for virtual machines
A RunStrategy
for virtual machines determines a virtual machine instance’s (VMI) behavior, depending on a series of conditions. The spec.runStrategy
setting exists in the virtual machine configuration process as an alternative to the spec.running
setting. The spec.runStrategy
setting allows greater flexibility for how VMIs are created and managed, in contrast to the spec.running
setting with only true
or false
responses. However, the two settings are mutually exclusive. Only either spec.running
or spec.runStrategy
can be used. An error occurs if both are used.
There are four defined RunStrategies.
Always
A VMI is always present when a virtual machine is created. A new VMI is created if the original stops for any reason, which is the same behavior as spec.running: true
.
RerunOnFailure
A VMI is re-created if the previous instance fails due to an error. The instance is not re-created if the virtual machine stops successfully, such as when it shuts down.
Manual
The start
, stop
, and restart
virtctl client commands can be used to control the VMI’s state and existence.
Halted
No VMI is present when a virtual machine is created, which is the same behavior as spec.running: false
.
Different combinations of the start
, stop
and restart
virtctl commands affect which RunStrategy
is used.
The following table follows a VM’s transition from different states. The first column shows the VM’s initial RunStrategy
. Each additional column shows a virtctl command and the new RunStrategy
after that command is run.
Initial RunStrategy | start | stop | restart |
---|---|---|---|
Always | - | Halted | Always |
RerunOnFailure | - | Halted | RerunOnFailure |
Manual | Manual | Manual | Manual |
Halted | Always | - | - |
In OKD Virtualization clusters installed using installer-provisioned infrastructure, when a node fails the MachineHealthCheck and becomes unavailable to the cluster, VMs with a RunStrategy of |
apiVersion: kubevirt.io/v1
kind: VirtualMachine
spec:
RunStrategy: Always (1)
template:
...
1 | The VMI’s current RunStrategy setting. |
Additional resources
The
VirtualMachineSpec
definition in the KubeVirt v0.49.0 API Reference provides broader context for the parameters and hierarchy of the virtual machine specification.The KubeVirt API Reference is the upstream project reference and might contain parameters that are not supported in OKD Virtualization.
See Prepare a container disk before adding it to a virtual machine as a
containerDisk
volume.See Deploying machine health checks for further details on deploying and enabling machine health checks.
See Installer-provisioned infrastructure overview for further details on installer-provisioned infrastructure.
See Configuring the SR-IOV Network Operator for further details on the SR-IOV Network Operator.