此内容没有您所选择的语言版本。
Chapter 5. Deploying a Quarkus application compiled to a native executable as a OpenShift Serverless service
As an application developer, you can deploy a Quarkus application compiled to a native executable 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.
You can run Quarkus as a native executable or as a Java application using OpenJDK. For native executables, use the Red Hat UBI 8 minimal image. For OpenJDK, use the Red Hat 8 UBI Java image.
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.