×

Changing the instance type of a VM

You can change the instance type associated with a running virtual machine (VM) by using the web console. The change takes effect immediately.

Prerequisites
  • You created the VM by using an instance type.

Procedure
  1. In the OKD web console, click VirtualizationVirtualMachines.

  2. Select a VM to open the VirtualMachine details page.

  3. Click the Configuration tab.

  4. On the Details tab, click the instance type text to open the Edit Instancetype dialog. For example, click 1 CPU | 2 GiB Memory.

  5. Edit the instance type by using the Series and Size lists.

    1. Select an item from the Series list to show the relevant sizes for that series. For example, select General Purpose.

    2. Select the VM’s new instance type from the Size list. For example, select medium: 1 CPUs, 4Gi Memory, which is available in the General Purpose series.

  6. Click Save.

Verification
  1. Click the YAML tab.

  2. Click Reload.

  3. Review the VM YAML to confirm that the instance type changed.

Hot plugging memory on a virtual machine

You can add or remove the amount of memory allocated to a virtual machine (VM) without having to restart the VM by using the OKD web console.

Procedure
  1. Navigate to VirtualizationVirtualMachines.

  2. Select the required VM to open the VirtualMachine details page.

  3. On the Configuration tab, click Edit CPU|Memory.

  4. Enter the desired amount of memory and click Save.

The system applies these changes immediately. If the VM is migratable, a live migration is triggered. If not, or if the changes cannot be live-updated, a RestartRequired condition is added to the VM.

Linux guests require a kernel version of 5.16 or later and Windows guests require the latest viomem drivers.

Hot plugging CPUs on a virtual machine

You can increase or decrease the number of CPU sockets allocated to a virtual machine (VM) without having to restart the VM by using the OKD web console.

Procedure
  1. Navigate to VirtualizationVirtualMachines.

  2. Select the required VM to open the VirtualMachine details page.

  3. On the Configuration tab, click Edit CPU|Memory.

  4. Select the vCPU radio button.

  5. Enter the desired number of vCPU sockets and click Save.

    If the VM is migratable, a live migration is triggered. If not, or if the changes cannot be live-updated, a RestartRequired condition is added to the VM.

Editing a virtual machine by using the command line

You can edit a virtual machine (VM) by using the command line.

Prerequisites
  • You installed the oc CLI.

Procedure
  1. Obtain the virtual machine configuration by running the following command:

    $ oc edit vm <vm_name>
  2. Edit the YAML configuration.

  3. If you edit a running virtual machine, you need to do one of the following:

    • Restart the virtual machine.

    • Run the following command for the new configuration to take effect:

      $ oc apply vm <vm_name> -n <namespace>

Adding a disk to a virtual machine

You can add a virtual disk to a virtual machine (VM) by using the OKD web console.

Procedure
  1. Navigate to VirtualizationVirtualMachines in the web console.

  2. Select a VM to open the VirtualMachine details page.

  3. On the Disks tab, click Add disk.

  4. Specify the Source, Name, Size, Type, Interface, and Storage Class.

    1. Optional: You can enable preallocation if you use a blank disk source and require maximum write performance when creating data volumes. To do so, select the Enable preallocation checkbox.

    2. Optional: You can clear Apply optimized StorageProfile settings to change the Volume Mode and Access Mode for the virtual disk. If you do not specify these parameters, the system uses the default values from the kubevirt-storage-class-defaults config map.

  5. Click Add.

If the VM is running, you must restart the VM to apply the change.

Storage fields

Field Description

Blank (creates PVC)

Create an empty disk.

Import via URL (creates PVC)

Import content via URL (HTTP or HTTPS 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 (a-z), numbers (0-9), hyphens (-), and periods (.), up to a maximum of 253 characters. The first and last characters must be alphanumeric. The name must not contain uppercase letters, spaces, or special characters.

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 storage settings

The following advanced storage settings are optional and available for Blank, Import via URL, and Clone existing PVC disks.

If you do not specify these parameters, the system uses the default storage profile values.

Parameter Option 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 Block if the underlying storage supports it.

Access Mode

ReadWriteOnce (RWO)

Volume can be mounted as read-write by a single node.

ReadWriteMany (RWX)

Volume can be mounted as read-write by many nodes at one time.

This mode is required for live migration.

Mounting a Windows driver disk on a virtual machine

You can mount a Windows driver disk on a virtual machine (VM) by using the OKD web console.

Procedure
  1. Navigate to VirtualizationVirtualMachines.

  2. Select the required VM to open the VirtualMachine details page.

  3. On the Configuration tab, click Storage.

  4. Select the Mount Windows drivers disk checkbox.

    The Windows driver disk is displayed in the list of mounted disks.

Adding a secret, config map, or service account to a virtual machine

You add a secret, config map, or service account to a virtual machine by using the OKD web console.

These resources are added to the virtual machine as disks. You then mount the secret, config map, or service account as you would mount any other disk.

If the virtual machine is running, changes do not take effect until you restart the virtual machine. The newly added resources are marked as pending changes at the top of the page.

Prerequisites
  • The secret, config map, or service account that you want to add must exist in the same namespace as the target virtual machine.

Procedure
  1. Click VirtualizationVirtualMachines from the side menu.

  2. Select a virtual machine to open the VirtualMachine details page.

  3. Click ConfigurationEnvironment.

  4. Click Add Config Map, Secret or Service Account.

  5. Click Select a resource and select a resource from the list. A six character serial number is automatically generated for the selected resource.

  6. Optional: Click Reload to revert the environment to its last saved state.

  7. Click Save.

Verification
  1. On the VirtualMachine details page, click ConfigurationDisks and verify that the resource is displayed in the list of disks.

  2. Restart the virtual machine by clicking ActionsRestart.

You can now mount the secret, config map, or service account as you would mount any other disk.

Updating multiple virtual machines

You can use the command line interface (CLI) to update multiple virtual machines (VMs) at the same time.

Prerequisites
  • You installed the oc CLI.

  • You have access to the OKD cluster, and you have cluster-admin permissions.

Procedure
  1. Create a privileged service account by running the following commands:

    $ oc adm new-project kubevirt-api-lifecycle-automation

    $ oc create sa kubevirt-api-lifecycle-automation -n kubevirt-api-lifecycle-automation

    $ oc create clusterrolebinding kubevirt-api-lifecycle-automation --clusterrole=cluster-admin --serviceaccount=kubevirt-api-lifecycle-automation:kubevirt-api-lifecycle-automation
  2. Determine the pull URL for the kubevirt-api-lifecycle image by running the following command:

    $ oc get csv -n openshift-cnv -l=operators.coreos.com/kubevirt-hyperconverged.openshift-cnv -ojson | jq '.items[0].spec.relatedImages[] | select(.name|test(".*kubevirt-api-lifecycle-automation.*")) | .image'
  3. Deploy Kubevirt-Api-Lifecycle-Automation by creating a job object as shown in the following example:

    apiVersion: batch/v1
    kind: Job
    metadata:
     name: kubevirt-api-lifecycle-automation
     namespace: kubevirt-api-lifecycle-automation
    spec:
     template:
      spec:
       containers:
       - name: kubevirt-api-lifecycle-automation
         image: quay.io/openshift-virtualization/kubevirt-api-lifecycle-automation:v4.19 (1)
         imagePullPolicy: Always
         env:
         - name: MACHINE_TYPE_GLOB (2)
           value: smth-glob9.10.0
         - name: RESTART_REQUIRED (3)
           value: "true"
         - name: NAMESPACE (4)
           value: "default"
         - name: LABEL_SELECTOR (5)
           value: my-vm
         securityContext:
          allowPrivilegeEscalation: false
          capabilities:
           drop:
           - ALL
          privileged: false
          runAsNonRoot: true
          seccompProfile:
           type: RuntimeDefault
       restartPolicy: Never
       serviceAccountName: kubevirt-api-lifecycle-automation
1 Replace the image value with your pull URL for the image.
2 Replace the MACHINE_TYPE_GLOB value with your own pattern. This pattern is used to detect deprecated machine types that need to be upgraded.
3 If the RESTART_REQUIRED emvironment variable is set to true, VMs are restarted after the machine type is updated. If you do not want VMs to be restarted, set the value to false.
4 The namespace environment value indicates the namespace to look for VMs in. Leave the parameter empty for the job to go over all namespaces in the cluster.
5 You can use the LABEL_SELECTOR environment variable to select VMs that receive the job action. If you want the job to go over all VMs in the cluster, do not assign a value to the parameter.

Configuring multiple IOThreads for fast storage access

You can improve storage performance by configuring multiple IOThreads for a virtual machine (VM) that uses fast storage, such as solid-state drive (SSD) or non-volatile memory express (NVMe). This configuration option is only available by editing YAML of the VM.

Multiple IOThreads are supported only when blockMultiQueue is enabled and the disk bus is set to virtio. You must set this configuration for the configuration to work correctly.

Procedure
  1. Click VirtualizationVirtualMachines from the side menu.

  2. Select a virtual machine to open the VirtualMachine details page.

  3. Click the YAML tab to open the VM manifest.

  4. In the YAML editor, locate the spec.template.spec.domain section and add or modify the following fields:

    domain:
      ioThreadsPolicy: supplementalPool
      ioThreads:
        supplementalPoolThreadCount: 4
      devices:
        blockMultiQueue: true
        disks:
        - name: datavolume
          disk:
            bus: virtio
    # ...
  5. Click Save.

The spec.template.spec.domain setting cannot be changed while the VM is running. You must stop the VM before applying the changes, and then restart the VM for the new settings to take effect.

Additional resources for config maps, secrets, and service accounts