1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-07 00:48:01 +01:00
Files
openshift-docs/modules/nw-exposing-service.adoc
2023-10-30 10:13:25 -04:00

146 lines
3.4 KiB
Plaintext

// Module included in the following assemblies:
//
// * networking/configuring_ingress_cluster_traffic/configuring-ingress-cluster-traffic-nodeport.adoc
ifeval::["{context}" == "configuring-ingress-cluster-traffic-nodeport"]
:nodeport:
endif::[]
:_mod-docs-content-type: PROCEDURE
[id="nw-exposing-service_{context}"]
= Exposing the service by creating a route
You can expose the service as a route by using the `oc expose` command.
.Procedure
To expose the service:
. Log in to {product-title}.
. Log in to the project where the service you want to expose is located:
+
[source,terminal]
----
$ oc project myproject
----
ifndef::nodeport[]
. Run the `oc expose service` command to expose the route:
+
[source,terminal]
----
$ oc expose service nodejs-ex
----
+
.Example output
[source,terminal]
----
route.route.openshift.io/nodejs-ex exposed
----
. To verify that the service is exposed, you can use a tool, such as cURL, to make sure the service is accessible from outside the cluster.
.. Use the `oc get route` command to find the route's host name:
+
[source,terminal]
----
$ oc get route
----
+
.Example output
[source,terminal]
----
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
nodejs-ex nodejs-ex-myproject.example.com nodejs-ex 8080-tcp None
----
.. Use cURL to check that the host responds to a GET request:
+
[source,terminal]
----
$ curl --head nodejs-ex-myproject.example.com
----
+
.Example output
[source,terminal]
----
HTTP/1.1 200 OK
...
----
endif::nodeport[]
ifdef::nodeport[]
. To expose a node port for the application, modify the custom resource definition (CRD) of a service by entering the following command:
+
[source,terminal]
----
$ oc edit svc <service_name>
----
+
.Example output
[source,yaml]
----
spec:
ports:
- name: 8443-tcp
nodePort: 30327 <1>
port: 8443
protocol: TCP
targetPort: 8443
sessionAffinity: None
type: NodePort <2>
----
<1> Optional: Specify the node port range for the application. By default, {product-title} selects an available port in the `30000-32767` range.
<2> Define the service type.
. Optional: To confirm the service is available with a node port exposed, enter the following command:
+
[source,terminal]
----
$ oc get svc -n myproject
----
+
.Example output
[source,terminal]
----
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nodejs-ex ClusterIP 172.30.217.127 <none> 3306/TCP 9m44s
nodejs-ex-ingress NodePort 172.30.107.72 <none> 3306:31345/TCP 39s
----
. Optional: To remove the service created automatically by the `oc new-app` command, enter the following command:
+
[source,terminal]
----
$ oc delete svc nodejs-ex
----
.Verification
* To check that the service node port is updated with a port in the `30000-32767` range, enter the following command:
+
[source,terminal]
----
$ oc get svc
----
+
In the following example output, the updated port is `30327`:
+
.Example output
[source,terminal]
----
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
httpd NodePort 172.xx.xx.xx <none> 8443:30327/TCP 109s
----
endif::nodeport[]
//Potentially add verification step, "If a verification step is needed, it would
//look something like oc get route mysql-55-rhel7 and curl with the host from the
//output of the oc get route command."
ifdef::nodeport[]
:!nodeport:
endif::[]