Skip to content

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.

Prerequisites
  • Install the OpenShift CLI (oc) and log in as a cluster administrator.

Procedure
  1. Create a new project for your service by running the oc new-project command:

    $ oc new-project <project_name>
  2. Use the oc new-app command to create your service:

    $ oc new-app nodejs:12~https://github.com/sclorg/nodejs-ex.git
  3. To verify that the service was created, run the following command:

    $ oc get svc -n <project_name>
    Example output
    NAME        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
    nodejs-ex   ClusterIP   172.30.197.157   <none>        8080/TCP   70s

    Note

    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.

Prerequisites
  • You logged into OpenShift Container Platform.

Procedure
  1. Log in to the project where the service you want to expose is located:

    $ oc project <project_name>
  2. Run the oc expose service command to expose the route:

    $ oc expose service nodejs-ex
    Example output
    route.route.openshift.io/nodejs-ex exposed
  3. To verify that the service is exposed, you can use a tool, such as curl to check that the service is accessible from outside the cluster.

    1. To find the hostname of the route, enter the following command:

      $ oc get route
      Example output
      NAME        HOST/PORT                        PATH   SERVICES    PORT       TERMINATION   WILDCARD
      nodejs-ex   nodejs-ex-myproject.example.com         nodejs-ex   8080-tcp                 None
    2. To check that the host responds to a GET request, enter the following command:

      Example curl command
      $ curl --head nodejs-ex-myproject.example.com
      Example output
      HTTP/1.1 200 OK
      ...