mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-06 06:46:26 +01:00
54 lines
1.6 KiB
Plaintext
54 lines
1.6 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * virt/virtual_machines/virt-accessing-vm-consoles.adoc
|
|
|
|
[id="virt-accessing-vmi-ssh_{context}"]
|
|
= 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
|
|
. Run the following command to create the `fedora-vm-ssh` service:
|
|
+
|
|
----
|
|
$ 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.
|
|
|
|
. Check the service to find out which port the service acquired:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc get svc
|
|
----
|
|
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
fedora-vm-ssh NodePort 127.0.0.1 <none> 22:32551/TCP 6s
|
|
----
|
|
+
|
|
In this example, the service acquired the `32551` port.
|
|
|
|
. 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:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ ssh username@<node_IP_address> -p 32551
|
|
----
|