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 Copy linkLink copied to clipboard!
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 logincommand. 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
$ oc new-project PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow For example, for the
microprofile-configquickstart, create a new project namedeap-demousing the following command.oc new-project eap-demo
$ oc new-project eap-demoCopy to Clipboard Copied! Toggle word wrap Toggle overflow
8.2. Building and Deploying JBoss EAP XP Application Images using S2I Copy linkLink copied to clipboard!
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 logincommand 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:
helm repo add jboss-eap https://jbossas.github.io/eap-charts/
$ helm repo add jboss-eap https://jbossas.github.io/eap-charts/Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Create a file named
helm.yamlusing the following YAML content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the following command to deploy your JBoss EAP XP application on Openshift.
helm install microprofile-config -f helm.yaml jboss-eap/eap-xp5
$ helm install microprofile-config -f helm.yaml jboss-eap/eap-xp5Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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.curl https://$(oc get route microprofile-config --template='{{ .spec.host }}')/config/value$ curl https://$(oc get route microprofile-config --template='{{ .spec.host }}')/config/valueCopy to Clipboard Copied! Toggle word wrap Toggle overflow You get the output
MyPropertyFileConfigValueconfirming that the application is deployed.
8.3. Completing post-deployment tasks for JBoss EAP XP source-to-image (S2I) application Copy linkLink copied to clipboard!
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.
oc get service
$ oc get serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Expose the main service as a route so you can access your application from outside of OpenShift. For example, for the
microprofile-configquickstart, use the following command to expose the required service and port.oc expose service/microprofile-config --port=8080
$ oc expose service/microprofile-config --port=8080Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the URL of the route.
oc get route
$ oc get routeCopy to Clipboard Copied! Toggle word wrap Toggle overflow Access the application in your web browser using the URL. The URL is the value of the
HOST/PORTfield 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/valuein 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-configquickstart, 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.
oc scale deploymentconfig DEPLOYMENTCONFIG_NAME --replicas=3
$ oc scale deploymentconfig DEPLOYMENTCONFIG_NAME --replicas=3Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example, for the
microprofile-configquickstart, use the following command to scale up the application.oc scale deployment/microprofile-config --replicas=3
$ oc scale deployment/microprofile-config --replicas=3Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional Resources
For more information about JBoss EAP XP Quickstarts, see the Use the Quickstarts section in the Using MicroProfile in JBoss EAP guide.