此内容没有您所选择的语言版本。
Deploying your Quarkus applications as OpenShift Serverless services
Abstract
Preface 复制链接链接已复制到粘贴板!
As an application developer, you can deploy a Quarkus application on Red Hat OpenShift Container Platform using OpenShift Serverless Knative Serving.
By using OpenShift Serverless Knative Serving, you can scale services up and down depending on the load size. Scaling down services that are currently not requested improves memory capabilities.
Quarkus is supported to run as a native executable or as a Java application using an OpenJDK. For native executables, use the Red Hat UBI 8 minimal image. For OpenJDK, use the Red Hat 8 UBI Java image.
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.
- OpenShift Serverless operator is installed and verified. See the Installing OpenShift Serverless guide for more details.
- OpenShift Knative Serving is installed and verified. See the Installing Knative Serving section of the Installing OpenShift Serverless guide for more details.
- For native compilation, a container environment like Podman or Docker is required.
-
Optionally install the
knCLI tool.
Currently, only Knative Serving is supported in the Red Hat build of Quarkus. Knative Eventing is currently tech preview.
Making open source more inclusive 复制链接链接已复制到粘贴板!
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.
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.
The following procedure demonstrates how to deploy a Serverless Quarkus Java application to OpenShift using the Quarkus OpenShift extension.
Prerequisites
- You have a Quarkus Maven project.
- OpenShift Serverless operator is installed.
- OpenShift Knative Serving is installed.
- You have access to a Red Hat OpenShift Container Platform cluster and the latest version of the OpenShift CLI (oc) is installed.
-
OpenJDK 11 is installed and the
JAVA_HOMEenvironment variable specifies the location of the Java SDK. - Apache Maven 3.6.2 or higher is installed. Maven is available from the Apache Maven Project website.
- For native compilation, a container environment like Podman or Docker is required.
-
The
knCLI tool is installed.
Procedure
- Change to the directory that contains your Quarkus project.
Add the OpenShift extension to an existing project:
./mvnw quarkus:add-extension -Dextensions="openshift"
./mvnw quarkus:add-extension -Dextensions="openshift"Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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 while in a development or testing environment, 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 8 image, add the following line to the
application.propertiesfile:quarkus.s2i.base-jvm-image=registry.access.redhat.com/ubi8/openjdk-11
quarkus.s2i.base-jvm-image=registry.access.redhat.com/ubi8/openjdk-11Copy to Clipboard Copied! Toggle word wrap Toggle overflow To direct OpenShift Serverless to pull your container image from the OpenShift internal registry, add the following line to the
application.propertiesfile:quarkus.container-image.registry=image-registry.openshift-image-registry.svc:5000
quarkus.container-image.registry=image-registry.openshift-image-registry.svc:5000Copy to Clipboard Copied! Toggle word wrap Toggle overflow To enable the creation of deployment descriptors for Knative Serving, add the following line to the
application.propertiesfile:quarkus.kubernetes.deployment-target=knative
quarkus.kubernetes.deployment-target=knativeCopy 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_name>is the name of your new project:oc new-project <project_name>
oc new-project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe
<project_name>should be the same as theusernameof the host system otherwise Quarkus cannot pull the image from the image registry. If you set a different<project_name>, make sure to add the following line to theapplication.propertiesfile:quarkus.container-image.group=<project_name>
quarkus.container-image.group=<project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To deploy your project to OpenShift, enter the following command:
./mvnw clean package -Dquarkus.kubernetes.deploy=true
./mvnw clean package -Dquarkus.kubernetes.deploy=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow To verify that the application was deployed correctly, run the following command:
kn service list
kn service listCopy to Clipboard Copied! Toggle word wrap Toggle overflow To view the full URL to the application, enter the following command where
<application_name>is the name of an application deployed in your OpenShift project:kn route describe <application_name> -o jsonpath='{.status.url}'kn route describe <application_name> -o jsonpath='{.status.url}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow
You can separate the native build, container build, and deployment steps when deploying a native serverless application. The following procedure demonstrates how to deploy a container image for a Quarkus native application in a continuous integration (CI) as a serverless application.
Prerequisites
- OpenShift Serverless operator is installed.
- OpenShift Knative Serving is installed.
- For native compilation, a container environment like Podman or Docker is required.
-
The
knCLI tool is installed.
Procedure
- Change to the directory that contains your Quarkus project.
Build a Linux executable using one of the following methods:
For Docker use:
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=registry.access.redhat.com/quarkus/mandrel-20-rhel8:20.3
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=registry.access.redhat.com/quarkus/mandrel-20-rhel8:20.3Copy to Clipboard Copied! Toggle word wrap Toggle overflow For Podman use:
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman -Dquarkus.native.builder-image=registry.access.redhat.com/quarkus/mandrel-20-rhel8:20.3
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman -Dquarkus.native.builder-image=registry.access.redhat.com/quarkus/mandrel-20-rhel8:20.3Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Open the
src/main/docker/Dockerfile.nativefile and set the<image_name>and<version>parameters:For Docker use:
docker build -f src/main/docker/Dockerfile.native -t <image_name>:<version> .
docker build -f src/main/docker/Dockerfile.native -t <image_name>:<version> .Copy to Clipboard Copied! Toggle word wrap Toggle overflow For Podman use:
podman build -f src/main/docker/Dockerfile.native -t <image_name>:<version>.
podman build -f src/main/docker/Dockerfile.native -t <image_name>:<version>.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Push the container to a repository that your CI environment and your OpenShift environment can access, where
<registry>is your registry URL:For Docker use:
docker tag <image_name>:<version> <registry>/<image_name>:<version> docker push <registry>/<image_name>:<version>
docker tag <image_name>:<version> <registry>/<image_name>:<version> docker push <registry>/<image_name>:<version>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For Podman use:
podman tag <image_name>:<version> <registry>/<image_name>:<version> podman push <registry>/<image_name>:<version>
podman tag <image_name>:<version> <registry>/<image_name>:<version> podman push <registry>/<image_name>:<version>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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_name>is the name of your new project:oc new-project <project_name>
oc new-project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To deploy your container as a serverless application using the OpenShift Serverless CLI (kn), enter the following command where
<service_name>is the name for your service:kn service create <service_name> --image REPOSITORY/<image_name>:<version>
kn service create <service_name> --image REPOSITORY/<image_name>:<version>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To verify that the service is ready, enter the following command.
kn service list <service_name>
kn service list <service_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output in the column called "READY" reads
trueif the service is ready.NoteThe
kn servicecommand returnstruewhen the necessary components are created, not when the image is pulled down and ready.
Chapter 3. Additional resources 复制链接链接已复制到粘贴板!
- For information about creating Quarkus applications with Maven, see Developing and compiling your Quarkus applications with Apache Maven.
- For more information on how to compile the Quarkus applications to native executables and native executable testing, see Compiling your Quarkus applications to native executables
- For information about deploying Quarkus Maven applications on Red Hat OpenShift Container Platform, see Deploying your Quarkus applications on Red Hat OpenShift Container Platform.
Revised on 2021-04-19 12:03:15 UTC