Chapter 4. Using S2I to deploy Red Hat build of Quarkus applications to OpenShift Container Platform
You can deploy your Quarkus applications to Red Hat OpenShift Container Platform by using the Source-to-Image (S2I) method. With S2I, you must provide the source code to the build container through a Git repository or by uploading the source code at build time.
The deployment procedure differs based on the Java version your Quarkus application uses.
4.1. Deploying Quarkus applications to OpenShift Container Platform with Java 17 Copy linkLink copied to clipboard!
You can deploy Quarkus applications that run Java 17 to OpenShift Container Platform by using the S2I method.
4.1.1. Prerequisites Copy linkLink copied to clipboard!
- You have a Quarkus application built with Java 17.
-
Optional: You have a Quarkus project that includes the
quarkus-openshiftextension. - You are working in the correct OpenShift project namespace.
- Your project is hosted in a Git repository.
4.1.2. Procedure Copy linkLink copied to clipboard!
Open the
pom.xmlfile, and set the Java version to 17:<maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Package your Java 17 application, by entering the following command:
./mvnw clean package
./mvnw clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Create a directory called
.s2iat the same level as thepom.xmlfile. Create a file called
environmentin the.s2idirectory and add the following content:MAVEN_S2I_ARTIFACT_DIRS=target/quarkus-app S2I_SOURCE_DEPLOYMENTS_FILTER=app lib quarkus quarkus-run.jar JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0 AB_JOLOKIA_OFF=true JAVA_APP_JAR=/deployments/quarkus-run.jar
MAVEN_S2I_ARTIFACT_DIRS=target/quarkus-app S2I_SOURCE_DEPLOYMENTS_FILTER=app lib quarkus quarkus-run.jar JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0 AB_JOLOKIA_OFF=true JAVA_APP_JAR=/deployments/quarkus-run.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Commit and push your changes to the remote Git repository.
Import the supported OpenShift Container Platform image by entering the following command:
oc import-image ubi9/openjdk-17 --from=registry.access.redhat.com/ubi9/openjdk-17 --confirm
oc import-image ubi9/openjdk-17 --from=registry.access.redhat.com/ubi9/openjdk-17 --confirmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note- If you are using the OpenShift image registry and pulling from image streams in the same project, your pod service account must already have the correct permissions.
- If you are pulling images across other OpenShift Container Platform projects or from secured registries, additional configuration steps might be required.
For more information, see the Red Hat Openshift Container Platform documentation.
Build the project, create the application, and deploy the OpenShift Container Platform service:
oc new-app registry.access.redhat.com/ubi9/openjdk-17~<git_path> --name=<project_name>
oc new-app registry.access.redhat.com/ubi9/openjdk-17~<git_path> --name=<project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<git_path>with the path of the Git repository that hosts your Quarkus project. For example,oc new-app registry.access.redhat.com/ubi9/openjdk-17~https://github.com/johndoe/code-with-quarkus.git --name=code-with-quarkus.If you do not have SSH keys configured for the Git repository, when specifying the Git path, use the HTTPS URL instead of the SSH URL.
-
Replace
<project_name>with the name of your application.
To deploy an updated version of the project, push changes to the Git repository, and then run:
oc start-build <project_name>
oc start-build <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To expose a route to the application, run the following command:
oc expose svc <project_name>
oc expose svc <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.1.3. Verification Copy linkLink copied to clipboard!
List the pods associated with your current OpenShift Container Platform project:
oc get pods
oc get podsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To get the log output for your application’s pod, run the following command, replacing
<pod_name>with the name of the latest pod prefixed by your application name:oc logs -f <pod_name>
oc logs -f <pod_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2. Deploying Quarkus applications to OpenShift Container Platform with Java 21 Copy linkLink copied to clipboard!
You can deploy Quarkus applications that run Java 21 to OpenShift Container Platform by using the S2I method.
4.2.1. Prerequisites Copy linkLink copied to clipboard!
-
Optional: You have a Quarkus Maven project that includes the
quarkus-openshiftextension. - You are working in the correct OpenShift Container Platform project namespace.
- Your project is hosted in a Git repository.
4.2.2. Procedure Copy linkLink copied to clipboard!
Open the
pom.xmlfile, and set the Java version to 21:<maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Package your Java 21 application, by entering the following command:
./mvnw clean package
./mvnw clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Create a directory called
.s2iat the same level as thepom.xmlfile. Create a file called
environmentin the.s2idirectory and add the following content:MAVEN_S2I_ARTIFACT_DIRS=target/quarkus-app S2I_SOURCE_DEPLOYMENTS_FILTER=app lib quarkus quarkus-run.jar JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0 AB_JOLOKIA_OFF=true JAVA_APP_JAR=/deployments/quarkus-run.jar
MAVEN_S2I_ARTIFACT_DIRS=target/quarkus-app S2I_SOURCE_DEPLOYMENTS_FILTER=app lib quarkus quarkus-run.jar JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0 AB_JOLOKIA_OFF=true JAVA_APP_JAR=/deployments/quarkus-run.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Commit and push your changes to the remote Git repository.
Import the supported OpenShift Container Platform image by entering the following command:
oc import-image ubi9/openjdk-21 --from=registry.access.redhat.com/ubi9/openjdk-21 --confirm
oc import-image ubi9/openjdk-21 --from=registry.access.redhat.com/ubi9/openjdk-21 --confirmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note- If you are using the OpenShift image registry and pulling from image streams in the same project, your pod service account must already have the correct permissions.
- If you are pulling images across other OpenShift Container Platform projects or from secured registries, additional configuration steps might be required. For more information, see the Red Hat Openshift Container Platform documentation.
-
If you are deploying on IBM Z infrastructure, enter
oc import-image ubi9/openjdk-21 --from=registry.redhat.io/ubi9/openjdk-21 --confirminstead. For information about this image, see Red Hat build of OpenJDK 21.
Build the project, create the application, and deploy the OpenShift Container Platform service:
oc new-app registry.access.redhat.com/ubi8/openjdk-21~<git_path> --name=<project_name>
oc new-app registry.access.redhat.com/ubi8/openjdk-21~<git_path> --name=<project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<git_path>with the path of the Git repository that hosts your Quarkus project. For example,oc new-app registry.access.redhat.com/ubi9/openjdk-21~https://github.com/johndoe/code-with-quarkus.git --name=code-with-quarkus.If you do not have SSH keys configured for the Git repository, when specifying the Git path, use the HTTPS URL instead of the SSH URL.
Replace
<project_name>with the name of your application.NoteIf you are deploying on IBM Z infrastructure, enter
oc new-app ubi9/openjdk-21~<git_path> --name=<project_name>instead.
To deploy an updated version of the project, push changes to the Git repository, and then run:
oc start-build <project_name>
oc start-build <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To expose a route to the application, run the following command:
oc expose svc <project_name>
oc expose svc <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2.3. Verification Copy linkLink copied to clipboard!
List the pods associated with your current OpenShift Container Platform project:
oc get pods
oc get podsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To get the log output for your application’s pod, run the following command, replacing
<pod_name>with the name of the latest pod prefixed by your application name:oc logs -f <pod_name>
oc logs -f <pod_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow