Chapter 8. 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.
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.
Default cloud-default-mp-config
layer provide a 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 5.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.
8.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.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc new-project PROJECT_NAME
$ oc new-project PROJECT_NAME
For example, for the
microprofile-config
quickstart, create a new project namedeap-demo
using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc new-project eap-demo
$ oc new-project eap-demo
8.2. Building and Deploying JBoss EAP XP Application Images using S2I
Follow the source-to-image (S2I) workflow to build reproducible container images for a JBoss EAP XP application. These generated container images include the application deployment and ready-to-run JBoss EAP XP servers.
The S2I workflow takes source code from a Git repository and injects it into a container that’s based on the language and framework you want to use. After the S2I workflow is completed, the src
code is compiled, the application is packaged and is deployed to the JBoss EAP XP server.
Prerequisites
- You have an active Red Hat customer account.
- You have a Registry Service Account. Follow the instructions on the Red Hat Customer Portal to create an authentication token using a registry service account.
- You have downloaded the OpenShift secret YAML file, which you can use to pull images from Red Hat Ecosystem Catalog. For more information, see OpenShift Secret.
-
You used the
oc login
command to log in to OpenShift. - You have installed Helm. For more information, see Installing Helm.
You have installed the repository for the JBoss EAP Helm charts by entering this command in the management CLI:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow helm repo add jboss-eap https://jbossas.github.io/eap-charts/
$ helm repo add jboss-eap https://jbossas.github.io/eap-charts/
Procedure
Create a file named
helm.yaml
using the following YAML content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow build: uri: https://github.com/jboss-developer/jboss-eap-quickstarts.git ref: XP_5.0.0.GA contextDir: microprofile-config mode: s2i deploy: replicas: 1
build: uri: https://github.com/jboss-developer/jboss-eap-quickstarts.git ref: XP_5.0.0.GA contextDir: microprofile-config mode: s2i deploy: replicas: 1
Use the following command to deploy your JBoss EAP XP application on Openshift.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow helm install microprofile-config -f helm.yaml jboss-eap/eap-xp5
$ helm install microprofile-config -f helm.yaml jboss-eap/eap-xp5
This procedure is very similar to Building application images using source-to-image in OpenShift. For more information about that procedure see Using JBoss EAP on OpenShift Container Platform.
Verification
Access the application using
curl
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow curl https://$(oc get route microprofile-config --template='{{ .spec.host }}')/config/value
$ curl https://$(oc get route microprofile-config --template='{{ .spec.host }}')/config/value
You get the output
MyPropertyFileConfigValue
confirming that the application is deployed.
8.3. 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.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc get service
$ oc get service
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.Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc expose service/microprofile-config --port=8080
$ oc expose service/microprofile-config --port=8080
Get the URL of the route.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc get route
$ oc get route
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.NoteFor JBoss EAP XP 5.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 behttp://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.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc scale deploymentconfig DEPLOYMENTCONFIG_NAME --replicas=3
$ oc scale deploymentconfig DEPLOYMENTCONFIG_NAME --replicas=3
For example, for the
microprofile-config
quickstart, use the following command to scale up the application.Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc scale deployment/microprofile-config --replicas=3
$ oc scale deployment/microprofile-config --replicas=3
Additional Resources
For more information about JBoss EAP XP Quickstarts, see the Use the Quickstarts section in the Using MicroProfile in JBoss EAP guide.