8.7.4.4. Create a service by using virtctl
You can create a service for a virtual machine (VM) with a single virtctl command. Choose the service type and the port to expose, such as port 22 for SSH access.
Prerequisites
-
You installed the
virtctlcommand-line tool. - You configured the cluster network to support the service.
-
The environment where you installed
virtctlhas the cluster permissions required to access the VM. For example, you ranoc loginor you set theKUBECONFIGenvironment variable.
Procedure
Create a service by running the following command:
$ virtctl expose vm <vm_name> --name <service_name> --type <service_type> --port <port>where:
<vm_name>- Specifies the name of the VM you are exposing.
<service_name>- Specifies a user-defined name for the service you are creating.
<service_type>-
Specifies one of
ClusterIP,NodePort, orLoadBalancer. <port>Specifies the network port on the VM that the service will expose.
Example:
$ virtctl expose vm example-vm --name example-service --type NodePort --port 22
Verification
Verify the service by running the following command:
$ oc get service