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.

Note

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

  1. Change to the directory that contains your Quarkus Maven project.
  2. To add the OpenShift extension to an existing project, enter the following command:

    ./mvnw quarkus:add-extension -Dextensions="openshift"
    Note

    You 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>
  3. 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
  4. 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
    Note

    If you are deploying on IBM Z infrastructure, add quarkus.s2i.base-jvm-image=registry.access.redhat.com/openj9/openj9-11-rhel8 to the application.properties file.

  5. To create an OpenShift route, add the following line to the application.properties file:

    quarkus.openshift.expose=true
  6. Save the changes to the application.properties file.
  7. Log in to the OpenShift CLI (oc):

    oc login
  8. 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
  9. To deploy your project to OpenShift, enter the following command in your Quarkus Maven project directory:

    ./mvnw clean package -Dquarkus.kubernetes.deploy=true
  10. To display the names and routes of all deployed applications in the OpenShift project, enter the following command:

    oc get route
  11. 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
  12. To create an HTTP request on the route’s hello endpoint, enter the following command:

    curl $URL/hello