Red Hat provides a container image for JBoss Enterprise Application Platform (JBoss EAP) that is specifically designed for use with OpenShift. In this tutorial we will learn how to pull the image from the registry and use it to deploy an application on OpenShift using S2I.
Setting up an OpenShift project
There are several strategies you can use to create an EAP application: in this example we will show how to use OpenShift Templates. First off, let’s create an openshift project for our example:
oc new-project eap-demo
Next, in order to use Red Hat images on OpenShift you need to access one of its Registries. The recommended registry to use is “registry.redhat.io” which requires authentication using your Red Hat Portal login. To verify that you are capable of authentication, you can log-in to the Registry using either docker or podman (Check this tutorial for an overview of Podman: Getting started with Podman)
docker login registry.redhat.io Username: username Password: password Login Succeeded!
Then, for environments where credentials will be shared, such as deployment systems, it is recommended to create a secret with a Service Account Tokens. A Service Account can be created at the following link: https://access.redhat.com/terms-based-registry/
Click on “New Service Account” and fill the Service account name:
Next, download it and execute it:
oc create -f 6340056_eapdemo_account.yaml
The secret will be added to your project. Now, you should be able to import the eap74-openjdk11-image-stream:
oc replace --force -f \ https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap74/eap74-openjdk11-image-stream.json
The above command should complete with the following output:
imagestream.image.openshift.io/jboss-eap74-openjdk11-openshift replaced imagestream.image.openshift.io/jboss-eap74-openjdk11-runtime-openshift replaced
Let’s now import the EAP 7.4 basic and https Templates so that we can use it to instantiate our application:
for resource in \ eap74-basic-s2i.json \ eap74-https-s2i.json do oc replace --force -f \ https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/eap74/templates/${resource} done
Great, now we will add an example application to our project. The application is the well-known kitchensink app, available in the EAP Quickstarts. You can create it as follows:
oc new-app --template=eap74-basic-s2i -p IMAGE_STREAM_NAMESPACE=eap-demo -p EAP_IMAGE_NAME=jboss-eap74-openjdk11-openshift:7.4.0 -p EAP_RUNTIME_IMAGE_NAME=jboss-eap74-openjdk11-runtime-openshift:7.4.0 -p SOURCE_REPOSITORY_URL=https://github.com/jboss-developer/jboss-eap-quickstarts -p SOURCE_REPOSITORY_REF=7.4.x -p CONTEXT_DIR=kitchensink
Verify that the Pod starts up:
$ oc get pods NAME READY STATUS RESTARTS AGE eap-app-1-deploy 1/1 Running 0 27s eap-app-1-hf5sz 0/1 Running 0 25s
The Route to access the application should be available as well:
oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD eap-app eap-app-eap-demo.apps-crc.testing eap-app <all> edge/Redirect None
You can reach the application at: eap-app-eap-demo.apps-crc.testing:
Using a slimmed EAP version
The EAP Project is provisioned through the Galleon project. You can choose to provision specific Galleon layers in your EAP image so that you will have an Image with a smaller footprint. To learn more about Galleon Layers I recommend checking this article: Provisioning WildFly with Galleon
To provision specific Galleon layers on OpenShift, use the Template parameter GALLEON_PROVISION_LAYERS and list your layers separated by a comma. For example, to build up the helloworld application from the quickstarts using just the jaxrs-server layer you can run the following command:
oc new-app --template=eap74-basic-s2i -p IMAGE_STREAM_NAMESPACE=eap-demo -p EAP_IMAGE_NAME=jboss-eap74-openjdk11-openshift:7.4.0 -p EAP_RUNTIME_IMAGE_NAME=jboss-eap74-openjdk11-runtime-openshift:7.4.0 -p SOURCE_REPOSITORY_URL=https://github.com/jboss-developer/jboss-eap-quickstarts -p SOURCE_REPOSITORY_REF=7.4.x -p GALLEON_PROVISION_LAYERS=jaxrs-server -p CONTEXT_DIR=helloworld