Accessing virtual machine consoles

OKD Virtualization provides different virtual machine consoles that you can use to accomplish different product tasks. You can access these consoles through the web console and by using CLI commands.

About virtual machine console sessions

You can connect to the VNC and serial consoles of a running virtual machine from the Console tab on the Virtual Machine Details page of the web console.

The VNC Console opens by default when you navigate to the Console tab. You can open a connection to the serial console by clicking the VNC Console drop-down list and selecting Serial Console.

Console sessions remain active in the background unless they are disconnected. To ensure that only one console session is open at a time, click the Disconnect before switching check box before switching consoles.

You can open the active console session in a detached window by clicking Open Console in New Window or by clicking ActionsOpen Console.

Options for the VNC Console

  • Send key combinations to the virtual machine by clicking Send Key.

Options for the Serial Console

  • Manually disconnect the Serial Console session from the virtual machine by clicking Disconnect.

  • Manually open a Serial Console session to the virtual machine by clicking Reconnect.

Connecting to the virtual machine with the web console

Connecting to the terminal

You can connect to a virtual machine by using the web console.

Procedure

  1. Ensure you are in the correct project. If not, click the Project list and select the appropriate project.

  2. Click WorkloadsVirtualization from the side menu.

  3. Click the Virtual Machines tab.

  4. Select a virtual machine to open the Virtual Machine Overview screen.

  5. In the Details tab, click the virt-launcher-<vm-name> pod.

  6. Click the Terminal tab. If the terminal is blank, select the terminal and press any key to initiate connection.

Connecting to the serial console

Connect to the Serial Console of a running virtual machine from the Console tab in the Virtual Machine Overview screen of the web console.

Procedure

  1. In the OKD Virtualization console, click WorkloadsVirtualization from the side menu.

  2. Click the Virtual Machines tab.

  3. Select a virtual machine to open the Virtual Machine Overview page.

  4. Click Console. The VNC console opens by default.

  5. Click the VNC Console drop-down list and select Serial Console.

  6. Optional: Open the serial console in a separate window by clicking Open Console in New Window.

Connecting to the VNC console

Connect to the VNC console of a running virtual machine from the Console tab in the Virtual Machine Overview screen of the web console.

Procedure

  1. In the OKD Virtualization console, click WorkloadsVirtualization from the side menu.

  2. Click the Virtual Machines tab.

  3. Select a virtual machine to open the Virtual Machine Overview page.

  4. Click the Console tab. The VNC console opens by default.

  5. Optional: Open the VNC console in a separate window by clicking Open Console in New Window.

Connecting to the RDP console

The desktop viewer console, which utilizes the Remote Desktop Protocol (RDP), provides a better console experience for connecting to Windows virtual machines.

To connect to a Windows virtual machine with RDP, download the console.rdp file for the virtual machine from the Consoles tab in the Virtual Machine Details screen of the web console and supply it to your preferred RDP client.

Prerequisites

  • A running Windows virtual machine with the QEMU guest agent installed. The qemu-guest-agent is included in the VirtIO drivers.

  • A layer-2 NIC attached to the virtual machine.

  • An RDP client installed on a machine on the same network as the Windows virtual machine.

Procedure

  1. In the OKD Virtualization console, click WorkloadsVirtualization from the side menu.

  2. Click the Virtual Machines tab.

  3. Select a Windows virtual machine to open the Virtual Machine Overview screen.

  4. Click the Console tab.

  5. In the Console list, select Desktop Viewer.

  6. In the Network Interface list, select the layer-2 NIC.

  7. Click Launch Remote Desktop to download the console.rdp file.

  8. Open an RDP client and reference the console.rdp file. For example, using remmina:

    1. $ remmina --connect /path/to/console.rdp
  9. Enter the Administrator user name and password to connect to the Windows virtual machine.

Accessing virtual machine consoles by using CLI commands

Accessing a virtual machine instance via SSH

You can use SSH to access a virtual machine (VM) after you expose port 22 on it.

The virtctl expose command forwards a virtual machine instance (VMI) port to a node port and creates a service for enabled access. The following example creates the fedora-vm-ssh service that forwards traffic from a specific port of cluster nodes to port 22 of the <fedora-vm> virtual machine.

Prerequisites

  • You must be in the same project as the VMI.

  • The VMI you want to access must be connected to the default pod network by using the masquerade binding method.

  • The VMI you want to access must be running.

  • Install the OpenShift CLI (oc).

Procedure

  1. Run the following command to create the fedora-vm-ssh service:

    1. $ virtctl expose vm <fedora-vm> --port=22 --name=fedora-vm-ssh --type=NodePort (1)
    1<fedora-vm> is the name of the VM that you run the fedora-vm-ssh service on.
  2. Check the service to find out which port the service acquired:

    1. $ oc get svc

    Example output

    1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    2. fedora-vm-ssh NodePort 127.0.0.1 <none> 22:32551/TCP 6s

    In this example, the service acquired the 32551 port.

  3. Log in to the VMI via SSH. Use the ipAddress of any of the cluster nodes and the port that you found in the previous step:

    1. $ ssh username@<node_IP_address> -p 32551

Accessing a virtual machine via SSH with YAML configurations

You can enable an SSH connection to a virtual machine (VM) without the need to run the virtctl expose command. When the YAML file for the VM and the YAML file for the service are configured and applied, the service forwards the SSH traffic to the VM.

The following examples show the configurations for the VM’s YAML file and the service YAML file.

Prerequisites

  • Install the OpenShift CLI (oc).

  • Create a namespace for the VM’s YAML file by using the oc create namespace command and specifying a name for the namespace.

Procedure

  1. In the YAML file for the VM, add the label and a value for exposing the service for SSH connections. Enable the masquerade feature for the interface:

    Example VirtualMachine definition

    1. ...
    2. apiVersion: kubevirt.io/v1
    3. kind: VirtualMachine
    4. metadata:
    5. namespace: ssh-ns (1)
    6. name: vm-ssh
    7. spec:
    8. running: false
    9. template:
    10. metadata:
    11. labels:
    12. kubevirt.io/vm: vm-ssh
    13. special: vm-ssh (2)
    14. spec:
    15. domain:
    16. devices:
    17. disks:
    18. - disk:
    19. bus: virtio
    20. name: containerdisk
    21. - disk:
    22. bus: virtio
    23. name: cloudinitdisk
    24. interfaces:
    25. - masquerade: {} (3)
    26. name: testmasquerade (4)
    27. rng: {}
    28. machine:
    29. type: ""
    30. resources:
    31. requests:
    32. memory: 1024M
    33. networks:
    34. - name: testmasquerade
    35. pod: {}
    36. volumes:
    37. - name: containerdisk
    38. containerDisk:
    39. image: kubevirt/fedora-cloud-container-disk-demo
    40. - name: cloudinitdisk
    41. cloudInitNoCloud:
    42. userData: |
    43. #!/bin/bash
    44. echo "fedora" | passwd fedora --stdin
    45. ...
    1Name of the namespace created by the oc create namespace command.
    2Label used by the service to identify the virtual machine instances that are enabled for SSH traffic connections. The label can be any key:value pair that is added as a label to this YAML file and as a selector in the service YAML file.
    3The interface type is masquerade.
    4The name of this interface is testmasquerade.
  2. Create the VM:

    1. $ oc create -f <path_for_the_VM_YAML_file>
  3. Start the VM:

    1. $ virtctl start vm-ssh
  4. In the YAML file for the service, specify the service name, port number, and the target port.

    Example Service definition

    1. ...
    2. apiVersion: v1
    3. kind: Service
    4. metadata:
    5. name: svc-ssh (1)
    6. namespace: ssh-ns (2)
    7. spec:
    8. ports:
    9. - targetPort: 22 (3)
    10. protocol: TCP
    11. port: 27017
    12. selector:
    13. special: vm-ssh (4)
    14. type: NodePort
    15. ...
    1Name of the SSH service.
    2Name of the namespace created by the oc create namespace command.
    3The target port number for the SSH connection.
    4The selector name and value must match the label specified in the YAML file for the VM.
  5. Create the service:

    1. $ oc create -f <path_for_the_service_YAML_file>
  6. Verify that the VM is running:

    1. $ oc get vmi

    Example output

    1. NAME AGE PHASE IP NODENAME
    2. vm-ssh 6s Running 10.244.196.152 node01
  7. Check the service to find out which port the service acquired:

    1. $ oc get svc

    Example output

    1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    2. svc-ssh NodePort 10.106.236.208 <none> 27017:30093/TCP 22s

    In this example, the service acquired the port number 30093.

  8. Run the following command to obtain the IP address for the node:

    1. $ oc get node <node_name> -o wide

    Example output

    1. NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP
    2. node01 Ready worker 6d22h v1.23.0 192.168.55.101 <none>
  9. Log in to the VM via SSH by specifying the IP address of the node where the VM is running and the port number. Use the port number displayed by the oc get svc command and the IP address of the node displayed by the oc get node command. The following example shows the ssh command with the username, node’s IP address, and the port number:

    1. $ ssh fedora@192.168.55.101 -p 30093

Accessing the serial console of a virtual machine instance

The virtctl console command opens a serial console to the specified virtual machine instance.

Prerequisites

  • The virt-viewer package must be installed.

  • The virtual machine instance you want to access must be running.

Procedure

  • Connect to the serial console with virtctl:

    1. $ virtctl console <VMI>

Accessing the graphical console of a virtual machine instances with VNC

The virtctl client utility can use the remote-viewer function to open a graphical console to a running virtual machine instance. This capability is included in the virt-viewer package.

Prerequisites

  • The virt-viewer package must be installed.

  • The virtual machine instance you want to access must be running.

If you use virtctl via SSH on a remote machine, you must forward the X session to your machine.

Procedure

  1. Connect to the graphical interface with the virtctl utility:

    1. $ virtctl vnc <VMI>
  2. If the command failed, try using the -v flag to collect troubleshooting information:

    1. $ virtctl vnc <VMI> -v 4

Connecting to a Windows virtual machine with an RDP console

The Remote Desktop Protocol (RDP) provides a better console experience for connecting to Windows virtual machines.

To connect to a Windows virtual machine with RDP, specify the IP address of the attached L2 NIC to your RDP client.

Prerequisites

  • A running Windows virtual machine with the QEMU guest agent installed. The qemu-guest-agent is included in the VirtIO drivers.

  • A layer 2 NIC attached to the virtual machine.

  • An RDP client installed on a machine on the same network as the Windows virtual machine.

Procedure

  1. Log in to the OKD Virtualization cluster through the oc CLI tool as a user with an access token.

    1. $ oc login -u <user> https://<cluster.example.com>:8443
  2. Use oc describe vmi to display the configuration of the running Windows virtual machine.

    1. $ oc describe vmi <windows-vmi-name>

    Example output

    1. ...
    2. spec:
    3. networks:
    4. - name: default
    5. pod: {}
    6. - multus:
    7. networkName: cnv-bridge
    8. name: bridge-net
    9. ...
    10. status:
    11. interfaces:
    12. - interfaceName: eth0
    13. ipAddress: 198.51.100.0/24
    14. ipAddresses:
    15. 198.51.100.0/24
    16. mac: a0:36:9f:0f:b1:70
    17. name: default
    18. - interfaceName: eth1
    19. ipAddress: 192.0.2.0/24
    20. ipAddresses:
    21. 192.0.2.0/24
    22. 2001:db8::/32
    23. mac: 00:17:a4:77:77:25
    24. name: bridge-net
    25. ...
  3. Identify and copy the IP address of the layer 2 network interface. This is 192.0.2.0 in the above example, or 2001:db8:: if you prefer IPv6.

  4. Open an RDP client and use the IP address copied in the previous step for the connection.

  5. Enter the Administrator user name and password to connect to the Windows virtual machine.