mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-07 09:46:53 +01:00
121 lines
2.7 KiB
Plaintext
121 lines
2.7 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::[]
|
|
|
|
[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 project1
|
|
----
|
|
|
|
ifndef::nodeport[]
|
|
. Run the following command to expose the route:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc expose service <service_name>
|
|
----
|
|
+
|
|
For example:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc expose service mysql-80-rhel7
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
route "mysql-80-rhel7" exposed
|
|
----
|
|
|
|
. Use a tool, such as cURL, to make sure you can reach the service using the
|
|
cluster IP address for the service:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ curl <pod_ip>:<port>
|
|
----
|
|
+
|
|
For example:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ curl 172.30.131.89:3306
|
|
----
|
|
+
|
|
The examples in this section use a MySQL service, which requires a client
|
|
application. If you get a string of characters with the `Got packets out of order`
|
|
message, you are connected to the service.
|
|
+
|
|
If you have a MySQL client, log in with the standard CLI command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ mysql -h 172.30.131.89 -u admin -p
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
Enter password:
|
|
Welcome to the MariaDB monitor. Commands end with ; or \g.
|
|
|
|
MySQL [(none)]>
|
|
----
|
|
endif::nodeport[]
|
|
ifdef::nodeport[]
|
|
. To expose a node port for the application, enter the following command. {product-title} automatically selects an available port in the `30000-32767` range.
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc expose dc mysql-80-rhel7 --type=NodePort --name=mysql-ingress
|
|
----
|
|
|
|
. 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
|
|
mysql-80-rhel7 ClusterIP 172.30.217.127 <none> 3306/TCP 9m44s
|
|
mysql-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 mysql-80-rhel7
|
|
----
|
|
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::[]
|