Red Hat Training

A Red Hat training course is available for Red Hat JBoss Developer Studio

Chapter 3. Deploying the OpenShift Container Platform 3 Resource

In this article, you use the s2i-spring-boot-cfx-jaxrs template in OpenShift Container Platform as an example to define resources for your OpenShift Container Platform application. Use similar steps to define resources for any other OpenShift Container Platform application.

Prerequisite

3.1. Deploying the s2i-spring-boot-cfx-jaxrs Template

Set up the IDE to work with CDK 3 as described in Using Container Development Kit 3.x Tooling in JBoss Developer Studio 11.x. The new connection for OpenShift Container Platform is listed in the OpenShift Explorer view, making the s2i-spring-boot-cfx-jaxrs template available for use.

To deploy the template:

  1. In the OpenShift Explorer view, expand the connection and right-click the {project name} and click New > Application.
  2. In the New OpenShift Application window:

    1. In the OpenShift project field, click the project that you want to create the new application in.
    2. In the Server application source tab, scroll through the list and locate and click s2i-spring-boot-cfx-jaxrs (quickstart, java, springboot, fis) - openshift.
  3. Click Finish.
  4. In the Create Application Summary window, click OK.
  5. In the Import OpenShift Application window in the Git Clone Location field, enter the location where you want to clone the template and click Finish.

    Figure 3.1. Selecting the s2i-spring-boot-cfx-jaxrs Template

    Selecting the s2i-spring-boot-cfx-jaxrs Template
  6. In the OpenShift Explorer view, expand the project, expand the s2i-spring-boot-cfx-jaxrs application and then right-click the s2i-spring-boot-cfx-jaxrs-1 build and click Build Log. The Console view shows the progress of the build.

Result: The Console view shows the latest: digest: sha256:{checksum} size: 9033 Push successful message.

3.2. Viewing the Application in the Web Console

Note

This section is required optionally if you want to see the application running on the terminal.

In absence of a service or route, you can view the application through the Pod tab in the web console.

To view the application in the Pod:

  1. In the web console, click Applications > Pod and then click the s2i-spring-boot-cfx-jaxrs-1 pod.
  2. Click the Logs tab.
  3. In the logs, locate Jolokia: Agent started with URL https://172.17.0.6:8778/jolokia/ and copy the IP address (172.17.0.6, in this example).
  4. Click the Terminal tab.
  5. In the terminal, type the following command: curl http://{IP_address}:8080/services/helloservice/sayHello.

    Example: curl http://172.17.0.6:8080/services/helloservice/sayHello

  6. Press Enter.
  7. Append the next line with: curl http://172.17.0.6:8080/services/helloservice/sayHello/{your_name} and press Enter.

    Example: curl http://172.17.0.6:8080/services/helloservice/sayHello/John

    Result: The Hello John, Welcome to CXF RS Spring Boot World!!! message appears, showing that application is up and running.

Figure 3.2. s2i-spring-boot-cfx-jaxrs Application in the Web Console

s2i-spring-boot-cfx-jaxrs Application in the Web Console

3.3. Defining Services and Routes Using a JSON File

Use the services-route.json file to create the service for the s2i-spring-boot-cfx-jaxrs application and then create a route for the service. In this case the target port is 8080 where the route sends the request to the application.

To define the resources:

  1. Copy the following content and paste it in a file, name the file services-routes.json, and save it.

    {
       "apiVersion": "v1",
       "kind": "List",
       "metadata": {},
       "items": [
          {
             "apiVersion": "v1",
             "kind": "Service",
             "metadata": {
                "name": "s2i-spring-boot-cxf-jaxrs"
             },
             "spec": {
                "ports": [
                   {
                      "name": "8080-tcp",
                      "protocol": "TCP",
                      "port": 8080,
                      "targetPort": 8080
                   },
                   {
                      "name": "8778-tcp",
                      "protocol": "TCP",
                      "port": 8778,
                      "targetPort": 8778
                   }
                ],
                "selector": {
                   "deploymentconfig": "s2i-spring-boot-cxf-jaxrs"
                }
             }
          },
          {
             "apiVersion": "v1",
             "kind": "Route",
             "metadata": {
                "name": "s2i-spring-boot-cxf-jaxrs"
             },
             "spec": {
                "to": {
                   "kind": "Service",
                   "name": "s2i-spring-boot-cxf-jaxrs",
                   "weight": 100
                },
                "port": {
                   "targetPort": "8080-tcp"
                },
                "wildcardPolicy": "None"
             }
          }
       ]
    }
  2. In the OpenShift Explorer view, right-click the project and click New > Resource.
  3. In the New OpenShift Resource window:

    1. In the OpenShift project list, click the project that you deployed the application to.
    2. In the Source pane, click Browse File System and locate and select the services-routes.json file.
    3. Click Finish.

      Figure 3.3. Selecting the service-routes.json File

      Selecting the service-routes.json File
  4. The Create Resource Summary window shows the details of the created service and route. Click OK.
  5. In the OpenShift Explorer view, right-click the project and click Show in > Web browser. The Whitelabel Error Page shows that the application has no explicit mapping.
  6. In the address bar, append the URL with services/helloservice/sayHello/. The URL should now look like: http://s2i-spring-boot-cxf-jaxrs-.{IP_address}.nip.io/services/helloservice/sayHello/.
  7. Press Enter. The web browser shows the Welcome to the CXF RS Spring Boot application, append /{name} to call the hello service message.
  8. At the end of the URL, append a name, for example: http://s2i-spring-boot-cxf-jaxrs-.{IP_address}.nip.io/services/helloservice/sayHello/John.

Result: The page displays the message: Hello John, Welcome to CXF RS Spring Boot World!!!

Figure 3.4. Viewing the s2i-spring-boot-cxf-jaxrs Application in the Web Browser

Viewing the s2i-spring-boot-cxf-jaxrs Application in the Web Browser