Configuring ingress cluster traffic by using an Ingress Controller
You can use the Ingress Controller to control how external users communicate with services that run inside the cluster.
Creating a project and service
If the project and service that you want to expose does not exist, create the project and then create the service.
If the project and service already exists, skip to the procedure on exposing the service to create a route.
-
Install the OpenShift CLI (
oc) and log in as a cluster administrator.
-
Create a new project for your service by running the
oc new-projectcommand:$ oc new-project <project_name> -
Use the
oc new-appcommand to create your service:$ oc new-app nodejs:12~https://github.com/sclorg/nodejs-ex.git -
To verify that the service was created, run the following command:
$ oc get svc -n <project_name>Example outputNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nodejs-ex ClusterIP 172.30.197.157 <none> 8080/TCP 70sNote
By default, the new service does not have an external IP address.
Exposing the service by creating a route
To enable external access to your application that runs on OpenShift Container Platform, you can expose the service as a route by using the oc expose command.
-
You logged into OpenShift Container Platform.
-
Log in to the project where the service you want to expose is located:
$ oc project <project_name> -
Run the
oc expose servicecommand to expose the route:$ oc expose service nodejs-exExample outputroute.route.openshift.io/nodejs-ex exposed -
To verify that the service is exposed, you can use a tool, such as
curlto check that the service is accessible from outside the cluster.-
To find the hostname of the route, enter the following command:
$ oc get routeExample outputNAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD nodejs-ex nodejs-ex-myproject.example.com nodejs-ex 8080-tcp None -
To check that the host responds to a GET request, enter the following command:
Examplecurlcommand$ curl --head nodejs-ex-myproject.example.comExample outputHTTP/1.1 200 OK ...
-