Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Deploying your Quarkus applications on Red Hat OpenShift Container Platform
Abstract
Preface Link kopierenLink in die Zwischenablage kopiert!
As an application developer, you can deploy a Quarkus application on Red Hat OpenShift Container Platform using Apache Maven and the quarkus-openshift extension in a single build command or you can use the traditional source-to-image (S2I) method. The resulting image from either method is fully supported. See the Development Support Scope of Coverage page for the build process and tools that are covered under development support.
Prerequisites
-
OpenJDK 11 is installed and the
JAVA_HOMEenvironment variable specifies the location of the Java SDK. Red Hat build of Open JDK is available from the Software Downloads page in the Red Hat Customer Portal (login required). - Apache Maven 3.6.2 or higher is installed. Maven is available from the Apache Maven Project website.
You have a Quarkus Maven project. For instructions on building a simple Quarkus application with Maven, see Getting started with Quarkus.
NoteFor a completed example of a Quarkus Maven project, download the Quarkus quickstart archive or clone the
Quarkus QuickstartsGit repository. The example is in thegetting-starteddirectory.- You have access to a Red Hat OpenShift Container Platform cluster and the latest version of the OpenShift CLI (oc) is installed. For information about installing oc, see the "Installing the CLI" section of the Installing and configuring OpenShift Container Platform clusters guide.
Chapter 1. Red Hat build of Quarkus Link kopierenLink in die Zwischenablage kopiert!
Red Hat build of Quarkus is a Kubernetes-native Java stack that is optimized for use with containers and Red Hat OpenShift Container Platform. Quarkus is designed to work with popular Java standards, frameworks, and libraries such as Eclipse MicroProfile, Apache Kafka, RESTEasy (JAX-RS), Hibernate ORM (JPA), Spring, Infinispan, and Apache Camel.
The Quarkus dependency injection solution is based on CDI (contexts and dependency injection) and includes an extension framework to expand functionality and to configure, boot, and integrate a framework into your application.
Quarkus provides a container-first approach to building Java applications. This approach makes it much easier to build microservices-based applications written in Java as well as enabling those applications to invoke functions running on serverless computing frameworks. For this reason, Quarkus applications have small memory footprints and fast start-up times.
Chapter 2. Red Hat OpenShift Container Platform Link kopierenLink in die Zwischenablage kopiert!
Red Hat OpenShift Container Platform is a Kubernetes-based platform for developing and running containerized applications. It is designed to enable applications and the data centers that support them to expand from just a few systems and applications to thousands of systems that serve millions of clients.
OpenShift supports two workflows for building container images for applications: the source and the binary workflows. Both workflows are based on the source-to-image (S2I) feature and both workflows rely on S2I builds using the source workflow. The key difference is that the source workflow generates deployable artifacts of your application inside OpenShift, while the binary workflow generates these binary artifacts outside of OpenShift. Both of them build the application container image inside OpenShift. The binary workflow provides an application binary as the source for an OpenShift S2I build that generates a container image.
Chapter 3. Using the Quarkus OpenShift extension to deploy Quarkus applications on OpenShift Link kopierenLink in die Zwischenablage kopiert!
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"
./mvnw quarkus:add-extension -Dextensions="openshift"Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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.xmlfile:<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using an untrusted certificate, add the following line to the
src/main/resources/application.propertiesfile:quarkus.kubernetes-client.trust-certs=true
quarkus.kubernetes-client.trust-certs=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow To direct OpenShift to use the Open JDK 11 Red Hat Enterprise Linux 7 image, add the following line to the
application.propertiesfile:quarkus.s2i.base-jvm-image=registry.access.redhat.com/openjdk/openjdk-11-rhel7
quarkus.s2i.base-jvm-image=registry.access.redhat.com/openjdk/openjdk-11-rhel7Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you are deploying on IBM Z infrastructure, add
quarkus.s2i.base-jvm-image=registry.access.redhat.com/openj9/openj9-11-rhel8to theapplication.propertiesfile.To create an OpenShift route, add the following line to the
application.propertiesfile:quarkus.openshift.expose=true
quarkus.openshift.expose=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Save the changes to the
application.propertiesfile. Log in to the OpenShift CLI (oc):
oc login
oc loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow To create a new OpenShift project, enter the following command where
PROJECT_NAMEis the name of your new project:oc new-project PROJECT_NAME
oc new-project PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow To deploy your project to OpenShift, enter the following command in your Quarkus Maven project directory:
./mvnw clean package -Dquarkus.kubernetes.deploy=true
./mvnw clean package -Dquarkus.kubernetes.deploy=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow To display the names and routes of all deployed applications in the OpenShift project, enter the following command:
oc get route
oc get routeCopy to Clipboard Copied! Toggle word wrap Toggle overflow To view the full URL to the application, where
APPLICATION_NAMEis 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/helloexport URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}')" echo "Application URL: $URL" curl $URL/helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow To create an HTTP request on the route’s
helloendpoint, enter the following command:curl $URL/hello
curl $URL/helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 4. Using S2I to deploy Quarkus applications on OpenShift Link kopierenLink in die Zwischenablage kopiert!
The traditional source-to-image (S2I) method is widely used as the preferred method for deploying applications on Red Hat OpenShift Container Platform. With S2I, you must provide the source code to the build container either through a Git repository or by uploading the source at build time. Use this method to deploy your Quarkus applications in production environments.
Prerequisites
- You have a Quarkus Maven project hosted in a Git repository.
Procedure
- Change to the directory that contains your Quarkus Maven project.
-
Create a hidden directory called
.s2iat the same level as thepom.xmlfile. Create a file called
environmentin the.s2idirectory and add the following content:ARTIFACT_COPY_ARGS=-p -r lib/ *-runner.jar
ARTIFACT_COPY_ARGS=-p -r lib/ *-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Commit and push your changes to the remote Git repository.
Log in to the OpenShift CLI (oc):
oc login
oc loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow To create a new OpenShift project, enter the following command where
PROJECT_NAMEis the name of your new project:oc new-project PROJECT_NAME
oc new-project PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow To import the supported OpenShift image, enter the following command:
oc import-image --confirm openjdk/openjdk-11-rhel7 --from=registry.access.redhat.com/openjdk/openjdk-11-rhel7
oc import-image --confirm openjdk/openjdk-11-rhel7 --from=registry.access.redhat.com/openjdk/openjdk-11-rhel7Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you are deploying on IBM Z infrastructure, enter
oc import-image --confirm openj9/openj9-11-rhel8 --from=registry.access.redhat.com/openj9/openj9-11-rhel8.For information about this image, see the Red Hat OpenJDK 11 Java Applications page.
To build the project in OpenShift, enter the following command where
GIT_PATHis the path to the Git repository that hosts your Quarkus project andPROJECT_NAMEis the OpenShift project that you created.oc new-app openjdk-11-rhel7 GIT_PATH --name=PROJECT_NAME
oc new-app openjdk-11-rhel7 GIT_PATH --name=PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you are deploying on IBM Z infrastructure, enter
oc new-app openj9/openj9-11-rhel8 GIT_PATH --name=PROJECT_NAME.This command builds the project, creates the application, and deploys the OpenShift service.
To create an OpenShift route, enter the following command:
oc expose service/PROJECT_NAME
oc expose service/PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow To view the new route, enter the following command where
APPLICATION_NAMEis the name of an application deployed in your OpenShift project:export URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}}')" echo "Application URL: $URL"export URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}}')" echo "Application URL: $URL"Copy to Clipboard Copied! Toggle word wrap Toggle overflow To create an HTTP request on the route’s
helloendpoint, enter the following command:curl $URL/hello
curl $URL/helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow - To use your application, enter the URL returned in the preceding command in a web browser.
To deploy an updated version of the project, push any updates to the Git repository then enter the following command:
oc start-build PROJECT_NAME
oc start-build PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow - Refresh your browser page after the build completes to see the changes.
Revised on 2020-12-08 20:07:33 UTC