How to access a Virtual Machine in a KubeOps Cluster

This guide provides instructions on how to access the virtual machine within your cluster.

If you’ve ever needed to log in to a custom virtual machine running in your KubeOps cluster, this guide is for you. In the steps ahead, we’ll cover the key prerequisites - such as having a KubeOps cluster with at least one master node, root privileges, a running virtual machine, and the correct credentials for the image inside that VM.

We’ll also walk through how to identify your VM instance using kubectl get vmi, locate the correct IP address, and finally access the machine via SSH. Along the way, we’ll discuss why KubeOps virtual machines aren’t exposed by default and how you can easily expose them if needed. Ready to get started? Let’s dive in!

Requirements

Make sure you have prepared the following points:

  • A KubeOps cluster with at least one master node and root privileges.
  • A running virtual machine in said cluster.
  • The credentials of the running image within the virtuial machine (username and password).

For example:

In the example shown, the custom vm is accessed via the Master Node**, Worker Node 1**, or Worker Node 2.

A KubeOps virtual machine is not exposed by default and therefore cannot be accessed remotely by the Admin Node. If necessary you can easily expose the VM, see [How to Expose a Virtual Machine](How to Expose a Virtual Machine).

Step 1 - Identify your Virtual Machine

  1. Login to the master or worker machine.
  2. Most kubeops software needs root privileges. Switch to root user.
sudo -i
  1. Identify your virtual machine by running the kubectl get vmi command.
kubectl get vmi -A

This command lists all virtual machine instances. Choose the IP of the desired virtual machine.

NAMESPACE   NAME         AGE   PHASE     IP              NODENAME       READY

kubevirt    [CUSTOMVM-1]   22h   Running   [192.168.16.XXX]   stackedadmin   True
kubevirt    [CUSTOMVM-2]   22h   Running   [192.168.16.YYY]   stackedadmin   True

Step 2 - Access the Virtual Machine

  1. Log in to the example VM remotely (e.g. using ssh). Use the IP address from the previous step. Use the credentials of the image. Replace [USERNAME] and [IP-ADDRESS] accordingly.
ssh [USERNAME]@[IP-ADDRESS].