Chapter 5. Build and run microservices applications on the OpenShift image for JBoss EAP XP

You can build and run your microservices applications on the OpenShift image for JBoss EAP XP.

Note

JBoss EAP XP is supported only on OpenShift 4 and later versions.

Use the following workflow to build and run a microservices application on the OpenShift image for JBoss EAP XP by using the source-to-image (S2I) process.

Note

The OpenShift images for JBoss EAP XP 1.0.0 provide a default standalone configuration file, which is based on the standalone-microprofile-ha.xml file. For more information about the server configuration files included in JBoss EAP XP, see the Standalone server configuration files section.

This workflow uses the microprofile-config quickstart as an example. The quickstart provides a small, specific working example that can be used as a reference for your own project. See the microprofile-config quickstart that ships with JBoss EAP XP 1.0.0 for more information.

Additional resources

5.1. Preparing OpenShift for application deployment

Prepare OpenShift for application deployment.

Prerequisites

You have installed an operational OpenShift instance. For more information, see the Installing and Configuring OpenShift Container Platform Clusters book on Red Hat Customer Portal.

Procedure

  1. Log in to your OpenShift instance using the oc login command.
  2. Create a new project in OpenShift.

    A project allows a group of users to organize and manage content separately from other groups. You can create a project in OpenShift using the following command.

    $ oc new-project PROJECT_NAME

    For example, for the microprofile-config quickstart, create a new project named eap-demo using the following command.

    $ oc new-project eap-demo

5.2. Configuring authentication to the Red Hat Container Registry

Before you can import and use the OpenShift image for JBoss EAP XP, you must configure authentication to the Red Hat Container Registry.

Create an authentication token using a registry service account to configure access to the Red Hat Container Registry. You need not use or store your Red Hat account’s username and password in your OpenShift configuration when you use an authentication token.

Procedure

  1. Follow the instructions on Red Hat Customer Portal to create an authentication token using a Registry Service Account management application.
  2. Download the YAML file containing the OpenShift secret for the token.

    You can download the YAML file from the OpenShift Secret tab on your token’s Token Information page.

  3. Create the authentication token secret for your OpenShift project using the YAML file that you downloaded:

    oc create -f 1234567_myserviceaccount-secret.yaml
  4. Configure the secret for your OpenShift project using the following commands, replacing the secret name below with the name of your secret created in the previous step.

    oc secrets link default 1234567-myserviceaccount-pull-secret --for=pull
    oc secrets link builder 1234567-myserviceaccount-pull-secret --for=pull

5.3. Importing the latest OpenShift image streams and templates for JBoss EAP XP

Import the latest OpenShift image streams and templates for JBoss EAP XP.

Procedure

  1. Use one of the following commands to import the latest JDK 8 and JDK 11 image streams and templates for the OpenShift image for JBoss EAP XP into your OpenShift project’s namespace.

    1. Import JDK 8 image streams:

      oc replace --force -f https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap-xp1/jboss-eap-xp1-openjdk8-openshift.json

      This command imports the following imagestreams and templates:

      • The JDK 8 builder imagestream: jboss-eap-xp1-openjdk8-openshift
      • The JDK 8 runtime imagestream: jboss-eap-xp1-openjdk8-runtime-openshift
    2. Import JDK 11 image stream:

      oc replace --force -f https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap-xp1/jboss-eap-xp1-openjdk11-openshift.json

      This command imports the following imagestreams and templates:

      • The JDK 11 builder imagestream: jboss-eap-xp1-openjdk11-openshift
      • The JDK 11 runtime imagestream: jboss-eap-xp1-openjdk11-runtime-openshift
    3. Import the JDK 8 and JDK 11 templates:

      for resource in \
      eap-xp1-basic-s2i.json \
      eap-xp1-third-party-db-s2i.json
      do
      oc replace --force -f https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap-xp1/templates/${resource}
      done
    Note

    The JBoss EAP XP image streams and templates imported using the above command are only available within that OpenShift project.

  2. If you have administrative access to the general openshift namespace and want the image streams and templates to be accessible by all projects, add -n openshift to the oc replace line of the command. For example:

    ...
    oc replace -n openshift --force -f \
    ...
  3. If you want to import the image streams and templates into a different project, add the -n PROJECT_NAME to the oc replace line of the command. For example:

    ...
    oc replace -n PROJECT_NAME --force -f
    ...

    If you use the cluster-samples-operator, see the OpenShift documentation on configuring the cluster samples operator. See https://docs.openshift.com/container-platform/latest/openshift_images/configuring-samples-operator.html for details about configuring the cluster samples operator.

5.4. Deploying a JBoss EAP XP source-to-image (S2I) application on OpenShift

Deploy a JBoss EAP XP source-to-image (S2I) application on OpenShift.

Prerequisites

Optional: A template can specify default values for many template parameters, and you might have to override some, or all, of the defaults. To see template information, including a list of parameters and any default values, use the command oc describe template TEMPLATE_NAME.

Procedure

  1. Create a new OpenShift application using the JBoss EAP XP image and your Java application’s source code. Use one of the provided JBoss EAP XP templates for S2I builds.

    $ oc new-app --template=eap-xp1-basic-s2i \ 1
     -p EAP_IMAGE_NAME=jboss-eap-xp1-openjdk8-openshift:1.0 \
     -p EAP_RUNTIME_IMAGE_NAME=jboss-eap-xp1-openjdk8-runtime-openshift:1.0 \
     -p IMAGE_STREAM_NAMESPACE=eap-demo \ 2
     -p SOURCE_REPOSITORY_URL=https://github.com/jboss-developer/jboss-eap-quickstarts \ 3
     -p SOURCE_REPOSITORY_REF=xp-1.0.x \ 4
     -p CONTEXT_DIR=microprofile-config 5
    1
    The template to use.
    2
    The latest images streams and templates were imported into the project’s namespace, so you must specify the namespace of where to find the image stream. This is usually the project’s name.
    3
    URL to the repository containing the application source code.
    4
    The Git repository reference to use for the source code. This can be a Git branch or tag reference.
    5
    The directory within the source repository to build.

    As another example, to deploy the microprofile-config quickstart using the JDK 11 runtime image enter the following command. The command uses the eap-xp1-basic-s2i template in the eap-demo project, created in the Preparing OpenShift for application deployment section, with the microprofile-config source code on GitHub.

    $ oc new-app --template=eap-xp1-basic-s2i \ 1
     -p EAP_IMAGE_NAME=jboss-eap-xp1-openjdk11-openshift:1.0 \
     -p EAP_RUNTIME_IMAGE_NAME=jboss-eap-xp1-openjdk11-runtime-openshift:1.0 \
     -p IMAGE_STREAM_NAMESPACE=eap-demo \ 2
     -p SOURCE_REPOSITORY_URL=https://github.com/jboss-developer/jboss-eap-quickstarts \ 3
     -p SOURCE_REPOSITORY_REF=xp-1.0.x \ 4
     -p CONTEXT_DIR=microprofile-config 5
    1
    The template to use.
    2
    The latest imagestreams and templates were imported into the project’s namespace, so you must specify the namespace where to find the imagestream. This is usually the project’s name.
    3
    URL to the repository containing the application source code.
    4
    The Git repository reference to use for the source code. This can be a Git branch or tag reference.
    5
    The directory within the source repository to build.
    Note

    A template can specify default values for many template parameters, and you might have to override some, or all, of the defaults. To see template information, including a list of parameters and any default values, use the command oc describe template TEMPLATE_NAME.

    You might also want to configure environment variables when creating your new OpenShift application.

  2. Retrieve the name of the build configurations.

    $ oc get bc -o name
  3. Use the name of the build configurations from the previous step to view the Maven progress of the builds.

    $ oc logs -f buildconfig/${APPLICATION_NAME}-build-artifacts
    
    …
    Push successful
    $ oc logs -f buildconfig/${APPLICATION_NAME}
    …
    Push successful

    For example, for the microprofile-config, the following command shows the progress of the Maven builds.

    $ oc logs -f buildconfig/eap-xp1-basic-app-build-artifacts
    
    …
    Push successful
    $ oc logs -f buildconfig/eap-xp1-basic-app
    …
    Push successful

5.5. Completing post-deployment tasks for JBoss EAP XP source-to-image (S2I) application

Depending on your application, you might need to complete some tasks after your OpenShift application has been built and deployed.

Examples of post-deployment tasks include the following:

  • Exposing a service so that the application is viewable from outside of OpenShift.
  • Scaling your application to a specific number of replicas.

Procedure

  1. Get the service name of your application using the following command.

    $ oc get service
  2. Optional: Expose the main service as a route so you can access your application from outside of OpenShift. For example, for the microprofile-config quickstart, use the following command to expose the required service and port.

    Note

    If you used a template to create the application, the route might already exist. If it does, continue on to the next step.

    $ oc expose service/eap-xp1-basic-app --port=8080
  3. Get the URL of the route.

    $ oc get route
  4. Access the application in your web browser using the URL. The URL is the value of the HOST/PORT field from previous command’s output.

    Note

    For JBoss EAP XP 1.0.0 GA distribution, the Microprofile Config quickstart does not reply to HTTPS GET requests to the application’s root context. This enhancement is only available in the JBoss EAP XP 1.0.1 GA distribution.

    For example, to interact with the Microprofile Config application, the URL might be http://HOST_PORT_Value/config/value in your browser.

    If your application does not use the JBoss EAP root context, append the context of the application to the URL. For example, for the microprofile-config quickstart, the URL might be http://HOST_PORT_VALUE/microprofile-config/.

  5. Optionally, you can scale up the application instance by running the following command. This command increases the number of replicas to 3.

    $ oc scale deploymentconfig DEPLOYMENTCONFIG_NAME --replicas=3

    For example, for the microprofile-config quickstart, use the following command to scale up the application.

    $ oc scale deploymentconfig/eap-xp1-basic-app --replicas=3

Additional Resources

For more information about JBoss EAP XP Quickstarts, see the Use the Quickstarts section in the Using Eclipse MicroProfile in JBoss EAP guide.