Bookmark this page

Creating and Accessing Virtual Machines

Objectives

  • Provision and access a new virtual machine.

Virtual Machine Creation

You can create a VM from a template by using the Virtual Machine Creation Wizard in the Red Hat OpenShift web console or by using YAML definitions through the web console or the command-line client.

Create a VM by Using the Wizard

The fastest way to create VMs is by using the wizard in the OpenShift web console. OpenShift provides default templates that include Red Hat Enterprise Linux, CentOS, Fedora, and Microsoft Windows Server. When using a default template, you must define a boot source. You can define many configuration options for the VM, including node scheduling rules, configuration maps and secrets, network interfaces, disk mounts, and labels. The following list includes key settings for the VM:

Project

The namespace where the VM resides.

Virtual Machine Name

The name of the VM to use in your Red Hat OpenShift cluster.

Authorized Key and SSH Access

Determines whether the VM is configured for SSH access, and which public SSH keys are copied to ~/.ssh/authorized_keys on the VM. Enabling SSH access creates a node port service within the VM's namespace. Enabling SSH access from outside the cluster requires additional configuration.

Start this VM after creation

Determines whether to power on the VM after provisioning, or to leave it powered off.

Virtual Machine Templates

Red Hat provides the default templates. These templates include settings to create generic systems with preconfigured networking, users, and storage. Default templates create a basic installation with settings that suit various needs. You can modify these templates to create templates with more specific settings. A modified template can include a specific boot source, additional storage, additional network interfaces, or other configuration differences.

You can create templates by using the Create Virtual Machine Template wizard or with a YAML definition. New templates start with no preconfigured content. You can create more specialized templates this way.

Initially, you can create templates only for the existing default operating systems. However, if you install the KubeVirt common-templates package in your OpenShift cluster, then you can create templates for other operating systems, such as Ubuntu or openSUSE.

Note

For more information about installing KubeVirt common templates, refer to https://cloud.redhat.com/blog/working-with-operating-system-templates-in-openshift-virtualization

Base Images

The cluster uses a base image to instantiate a VM. This base can be a cloud image or an installation disk image. Cloud images are in either RAW or QCOW2 format and can be compressed with gz or xz compression.

Operating system providers that create images in these formats generally release them alongside the general ISO-based installation disk image. You can also use base operating system images from container registries, such as Quay.io. Default templates include a prompt with an example of where to obtain an image for each source. You can also use an existing Persistent Volume Claim (PVC) as a base image. This option creates a clone of the PVC to use with the new VM. Cloning existing PVCs is a quick way to create copies of an existing VM.

YAML Definition

As an alternative to using a wizard for VM creation, you can also use YAML definition. You can define YAML from either the web console or from the command line with a text editor. Use YAML also to create VM templates. For both VMs and templates, the web console provides an editable default YAML configuration. The YAML file includes all the settings from the wizard in one structured document. You can adjust labels, modify system resources, define a base image, and change advanced options in one location by using the YAML editor.

You can also use the command line to edit a YAML configuration by using the oc edit command. This command opens an object's YAML configuration in your default text editor. To apply your changes, save the YAML configuration. The cluster applies changes to the resource when the editor's buffer is written.

Components of Virtual Machine Creation

Red Hat OpenShift uses several components to provide virtualization. The cluster structures components in a hierarchy, where higher components (such as virt-controller) orchestrate lower components (such as the virt-handler daemon set and the VM pod).

Figure 2.3: Components of virtual machine creation
virt-controller operator

The virt-controller operator monitors for new Virtual Machine Instance (VMI) objects. When a new VMI object is detected, the virt-controller operator creates a pod for the VMI and then assigns the pod to a node. The virt-controller then updates the VM with the node name.

virt-handler daemon set

The virt-handler daemon set runs on each node to execute any necessary actions to meet a VM's object defined state and to monitor for changes to a VM object. When a change is detected, the ` virt-handler` daemon set instructs the virt-launcher container to perform the required actions.

virt-launcher container

The virt-launcher container runs within each VM's pod and instantiates the VM by using a local libvirtd instance.

libvirtd instance

The libvirtd instance provides a low-level virtualization architecture and interface with the kernel to manage the lifecycle of the VM process.

Virtual Machine Management

Each VM has a management page that contains information about the VM, an interface to the VM's console, and controls for VM operations.

From a VM's management page, click Actions for administrative operations such as starting and stopping a VM.

Element Description
OverviewContains a log of cluster-level VM events, general details about the VM, resource utilization, and status information.
DetailsContains detailed information about the components of the VM.
MetricsDisplays CPU and memory utilization, storage metrics, network traffic metrics, and VM migration metrics.
YAMLProvides an interface to edit the VM's YAML configuration.
ConfigurationProvides access to five configuration subsections.
ConfigurationDisks Lists the disks and file systems that a VM uses. From this tab, you can edit, add, or delete a VM's disks and observe details of a VM's file.
ConfigurationNetwork Interfaces Contains the network interfaces that are connected to a VM. You can also use this tab to manage the connected network interfaces.
ConfigurationScheduling Enables managing the node scheduling and resource requirements such as node selector rules, toleration rules, and the affinity rules. Also use this section to manage the node migration strategy for the VM.
ConfigurationEnvironment Enables you to map configuration maps, secrets, or service accounts to a disk. The VM then mounts the disk.
ConfigurationScripts Manages the cloud-init username and password. Also use this section to inject authorized SSH keys to access the VM.
EventsContains a detailed and customizable event log.
ConsoleProvides a serial and Virtual Network Computing (VNC) console to access a VM directly.
SnapshotsLists and manages a VM's snapshots.
DiagnosticsDisplays the status condition of the VM and the volume snapshot status.

Accessing Virtual Machines

You can access your VMs in several ways:

Web Console Virtual Machine Interface

To access the VNC and serial interface for a VM from the OpenShift web console, navigate to VirtualizationVirtualMachines, select the VM's project, click the VM name, and then click the Console tab.

  • The VNC console enables video access to the VM and enables graphical operations.

  • The serial console provides a direct serial connection and command-line access to a VM. When using the serial console, you might need to press Enter a few times for a prompt to appear.

Command-line Virtual Machine Interface

You can also access the serial or VNC consoles of a VM through the virtctl command-line tool. The virtctl tool is a client application for managing and connecting to VMs that are hosted in OpenShift or KubeVirt environments.

To access OpenShift VMs with the virtctl tool, you must first log in to the OpenShift cluster with the oc login command. The virtctl tool can then reference the Kubernetes configuration that the oc client creates. Select the VM's project with the oc project vm-project-name command.

  • To access the serial console of a VM, use the following command. The escape character for the serial console is Ctrl-.

    [user@host ~]$ virtctl console vm-name
    Successfully connected to vm-name console. The escape sequence is ^]
    
    ...output omitted...
  • To access the VNC or graphical interface of a VM, use the following command:

    [user@host ~]$ virtctl vnc vm-name
    ...output omitted...
Other VNC Clients

The virtctl tool calls the remote-viewer application, which requires a separate installation by default on Linux for VNC. You can use other VNC clients by passing the --proxy-only flag to the virtctl vnc command.

Use the port that is provided in your chosen VNC application to connect to your VM. Some other popular VNC applications are TigerVNC and TightVNC.

References

For more information about working with YAML templates, see the Using templates guide in the Red Hat OpenShift Container Platform 4.14 documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/images/index#using-templates

For more information about installing the virtctl client, see the Installing virtctl guide in the Red Hat OpenShift Container Platform 4.14 documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/virtualization/index#installing-virtctl_virt-using-the-cli-tools

For more information about using virtctl, see the Using the virtctl and libguestfs CLI tools guide in the Red Hat OpenShift Container Platform 4.14 documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/virtualization/index#virt-using-the-cli-tools

Revision: do316-4.14-d8a6b80