이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 5. Deploying Quarkus applications as an OpenShift Serverless service
You can deploy your Quarkus applications to OpenShift Serverless using the Docker build strategy. 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.
Your Quarkus project includes pre-generated Dockerfiles with instructions. When you want to use a custom Dockerfile, you need to add the file in the src/main/docker directory or anywhere inside the module. Additionally, you need to set the path to your Dockerfile using the quarkus.openshift.jvm-dockerfile property for JVM mode and quarkus.openshift.native-dockerfile property for native mode.
The following procedure demonstrates how to deploy a Serverless Quarkus Java application or a Serverless application compiled to a native executable using the Quarkus OpenShift extension.
Prerequisites
-
Have a Quarkus Maven project that includes the
quarkus-openshiftextension. Login to OpenShift using
ocand select your project.- To verify the OpenShift project namespace, see Verifying the OpenShift project namespace.
- OpenShift Serverless operator is installed.
- OpenShift Knative Serving is installed and verified. See Installing Knative Serving.
- For native compilation, a Linux X86_64 operating system or an OCI (Open Container Initiative) compatible container runtime, such as Podman or Docker is required.
Procedure
- Change to the directory that contains your Quarkus project.
Configure the following properties in your
application.propertiesfile:Set Knative as a deployment target:
quarkus.kubernetes.deployment-target=knative
quarkus.kubernetes.deployment-target=knativeCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the Docker build strategy:
quarkus.openshift.build-strategy=docker
quarkus.openshift.build-strategy=dockerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Direct OpenShift Serverless to pull your container image from the OpenShift internal registry:
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 NoteIf your OpenShift
<project_name>is different from theusernameof the host system, set the group for the container image otherwise Quarkus cannot pull the image from the image registry.quarkus.container-image.group=<project_name>
quarkus.container-image.group=<project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) If you are using an untrusted certificate, configure the
KubernetesClient:quarkus.kubernetes-client.trust-certs=true
quarkus.kubernetes-client.trust-certs=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) Expose the service to create an OpenShift route:
quarkus.openshift.expose=true
quarkus.openshift.expose=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) Set the path to your custom Dockerfile:
quarkus.openshift.jvm-dockerfile=<path_to_your_dockerfile>
quarkus.openshift.jvm-dockerfile=<path_to_your_dockerfile>Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following example shows the path to the
Dockerfile.custom-jvm:quarkus.openshift.jvm-dockerfile=src/main/resources/Dockerfile.custom-jvm
quarkus.openshift.jvm-dockerfile=src/main/resources/Dockerfile.custom-jvmCopy to Clipboard Copied! Toggle word wrap Toggle overflow
(Optional) To deploy a Serverless application compiled to a native executable, you need to configure the following properties:
Set the container runtime:
quarkus.native.container-build=true
quarkus.native.container-build=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Specify the container engine:
To build a native executable with Podman:
quarkus.native.container-runtime=podman
quarkus.native.container-runtime=podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow To build a native executable with Docker:
quarkus.native.container-runtime=docker
quarkus.native.container-runtime=dockerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
(Optional) Set the path to your custom Dockerfile:
quarkus.openshift.native-dockerfile=<path_to_your_dockerfile>
quarkus.openshift.native-dockerfile=<path_to_your_dockerfile>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Package and deploy your Serverless application to OpenShift using one of the following options:
Deploy a Quarkus Java application:
./mvnw clean package -Dquarkus.kubernetes.deploy=true
./mvnw clean package -Dquarkus.kubernetes.deploy=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy a Quarkus native application:
./mvnw clean package -Pnative -Dquarkus.kubernetes.deploy=true
./mvnw clean package -Pnative -Dquarkus.kubernetes.deploy=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
View a list of pods associated with your current OpenShift project:
oc get pods
oc get podsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To retrieve the log output for your application’s pod, enter the following command where
<pod_name>is the name of the latest pod prefixed with the name of your application:oc logs -f <pod_name>
oc logs -f <pod_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow