Background
For most of us sshing into a VMware VM or an OpenShift Virtualization VM is pretty straightforward assuming the sshd
service is running on the VM and it’s connected to a public network.
In OpenShift Virtualization, though you have the option to deploy a VM on a private/internal network - what we call the pod network. When a VM is running on this pod network sshing into it from your laptop or from an external network can be a bit trickier.
Below, I will walk you through two different ways to ssh into a virtual machine running on OpenShift Virtualization. One method uses the virtctl ssh
command, and the other uses standard ssh
via port forwarding to the OpenShift pod running the VM. Both approaches provide identical access to the VM.
Virtual Machine Setup
Let’s assume you have already deployed a RHEL 8 VM, either through the OpenShift web console or using the virtctl
or oc
CLI.
Let’s start by checking the current status of our VM in the cluster.
Now, let’s check the running pod for our VM. We will need its name and the namespace it is deployed in for the next steps.
Let’s check the ssh settings on our RHEL 8 VM and make sure the public key has been added properly.
Finally, let’s log in to our OpenShift Virtualization cluster and check its status.
1 - virtctl ssh option
Let’s make sure our virtual machine is up and running.
Now let's use the virtctl ssh command to directly ssh into the virtual machine.
You will notice that the following "virtctl"
commands run in the background after executing the "virtctl ssh"
command.
2 - standard ssh via port-forward option
Let's set up port forwarding from local port 2222 to port 22 on the pod running our virtual machine. In this example, we won't be using a NodePort or LoadBalancer.
Now, we can use the standard ssh
command in a separate terminal window to connect to our virtual machine.
Conclusion
There are other ways to ssh into your virtual machine, such as using the OpenShift Virtualization web console. In this blog, I demonstrated how to achieve the same result from the command line when connecting to a virtual machine deployed on the pod network.