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 4.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 4.0.0 for more information. Additional resources For more information about the server configuration files included in JBoss EAP XP, see Standalone server configuration files . 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 Log in to your OpenShift instance using the oc login command. 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. For example, for the microprofile-config quickstart, create a new project named eap-demo using the following command. 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 Follow the instructions on Red Hat Customer Portal to create an authentication token using a Registry Service Account management application . 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. Create the authentication token secret for your OpenShift project using the YAML file that you downloaded: 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 step. Additional resources Configuring authentication to the Red Hat Container Registry Registry Service Account management application Configuring access to secured registries 5.3. Importing the latest OpenShift imagestreams and templates for JBoss EAP XP Import the latest OpenShift imagestreams and templates for JBoss EAP XP. Important OpenJDK 8 images and imagestreams on OpenShift are deprecated. The images and imagestreams are still supported on OpenShift. However, no enhancements are made to these images and imagestreams and they might be removed in the future. Red Hat continues to provide full support and bug fixes OpenJDK 8 images and imagestreams under its standard support terms and conditions. Procedure To import the latest imagestreams and templates for the OpenShift image for JBoss EAP XP into your OpenShift project's namespace, use the following commands: Import JDK 11 imagestream: This command imports the following imagestreams and templates: The JDK 11 builder imagestream: jboss-eap-xp4-openjdk11-openshift The JDK 11 runtime imagestream: jboss-eap-xp4-openjdk11-runtime-openshift Import the OpenShift templates: Note The JBoss EAP XP imagestreams and templates imported using the above command are only available within that OpenShift project. If you have administrative access to the general openshift namespace and want the imagestreams and templates to be accessible by all projects, add -n openshift to the oc replace line of the command. For example: If you want to import the imagestreams and templates into a different project, add the -n PROJECT_NAME to the oc replace line of the command. For example: If you use the cluster-samples-operator, see the OpenShift documentation on configuring the cluster samples operator. See Configuring the Cluster Samples Operator 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 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. 1 The template to use. The application image is tagged with the latest tag. 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 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. Retrieve the name of the build configurations. Use the name of the build configurations from the step to view the Maven progress of the builds. For example, for the microprofile-config , the following command shows the progress of the Maven builds. Additional resources Importing the latest OpenShift imagestreams and templates for JBoss EAP XP . Preparing OpenShift for application deployment . 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 Get the service name of your application using the following command. 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 step. Get the URL of the route. Access the application in your web browser using the URL. The URL is the value of the HOST/PORT field from command's output. Note For JBoss EAP XP 4.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 {JBossXPShortName101} 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/ . Optionally, you can scale up the application instance by running the following command. This command increases the number of replicas to 3. For example, for the microprofile-config quickstart, use the following command to scale up the application. Additional Resources For more information about JBoss EAP XP Quickstarts, see the JBoss EAP XP quickstart .

Commands:
oc new-project PROJECT_NAME
oc new-project eap-demo
create -f 1234567_myserviceaccount-secret.yaml
secrets link default 1234567-myserviceaccount-pull-secret --for=pull secrets link builder 1234567-myserviceaccount-pull-secret --for=pull
replace --force -f https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap-xp4/eap-xp4-openjdk11-image-stream.json
replace --force -f https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap-xp4/templates/eap-xp4-basic-s2i.json
replace -n openshift --force -f
replace -n PROJECT_NAME --force -f
oc new-app --template=eap-xp4-basic-s2i \ 1 -p EAP_IMAGE_NAME=jboss-eap-xp4-openjdk11-openshift:latest -p EAP_RUNTIME_IMAGE_NAME=jboss-eap-xp4-openjdk11-runtime-openshift:latest -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-4.0.x \ 4 -p CONTEXT_DIR=microprofile-config 5
oc get bc -o name
oc logs -f buildconfig/USD{APPLICATION_NAME}-build-artifacts ... Push successful oc logs -f buildconfig/USD{APPLICATION_NAME} ... Push successful
oc logs -f buildconfig/eap-xp4-basic-app-build-artifacts ... Push successful oc logs -f buildconfig/eap-xp4-basic-app ... Push successful
oc get service
oc expose service/eap-xp4-basic-app --port=8080
oc get route
oc scale deploymentconfig DEPLOYMENTCONFIG_NAME --replicas=3
oc scale deploymentconfig/eap-xp4-basic-app --replicas=3