Chapter 3. Using the Quarkus OpenShift extension to deploy Quarkus applications on OpenShift
The traditional source-to-image (S2I) source workflow generates the deployable artifacts of your application inside OpenShift. The Quarkus OpenShift extension uses the S2I binary workflow to provide a more streamlined deployment process. Instead of building from the source, the extension uploads the JAR files from the local file system. As a result, the build process is up to ten times faster than the traditional S2I method. You can use the Quarkus OpenShift extension when developing locally as well as from a build server or continuous integration (CI) system to perform repeatable builds from source.
Use the Quarkus OpenShift extension for development and testing purposes only. For production environments, consider using the traditional S2I method described in Chapter 4, Using S2I to deploy Quarkus applications on OpenShift.
Procedure
- Change to the directory that contains your Quarkus Maven project.
To add the OpenShift extension to an existing project, enter the following command:
./mvnw quarkus:add-extension -Dextensions="openshift"
NoteYou can include the
-Dextensions="openshift"
argument to add the Quarkus OpenShift extension when you create a new project.When you add the OpenShift extension, the script adds the following dependency to the
pom.xml
file:<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency>
If you are using an untrusted certificate, add the following line to the
src/main/resources/application.properties
file:quarkus.kubernetes-client.trust-certs=true
To direct OpenShift to use the Open JDK 11 Red Hat Enterprise Linux 7 image, add the following line to the
application.properties
file:quarkus.s2i.base-jvm-image=registry.access.redhat.com/openjdk/openjdk-11-rhel7
NoteIf you are deploying on IBM Z infrastructure, add
quarkus.s2i.base-jvm-image=registry.access.redhat.com/openj9/openj9-11-rhel8
to theapplication.properties
file.To create an OpenShift route, add the following line to the
application.properties
file:quarkus.openshift.expose=true
-
Save the changes to the
application.properties
file. Log in to the OpenShift CLI (oc):
oc login
To create a new OpenShift project, enter the following command where
PROJECT_NAME
is the name of your new project:oc new-project PROJECT_NAME
To deploy your project to OpenShift, enter the following command in your Quarkus Maven project directory:
./mvnw clean package -Dquarkus.kubernetes.deploy=true
To display the names and routes of all deployed applications in the OpenShift project, enter the following command:
oc get route
To view the full URL to the application, where
APPLICATION_NAME
is the name of an application deployed in your OpenShift project, enter the following command:export URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}')" echo "Application URL: $URL" curl $URL/hello
To create an HTTP request on the route’s
hello
endpoint, enter the following command:curl $URL/hello