Chapter 3. Deploying Quarkus Java applications to OpenShift
By using the Quarkus OpenShift extension, you can deploy your application to OpenShift using the Docker build strategy. The container is built inside the OpenShift cluster and provided as an image stream.
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.
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.
Procedure
- Change to the directory that contains your Quarkus project.
Configure the following properties in your
application.propertiesfile:Set the Docker build strategy:
quarkus.openshift.build-strategy=docker
quarkus.openshift.build-strategy=dockerCopy 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
Package and deploy your Quarkus application to the current OpenShift project:
./mvnw clean package -Dquarkus.kubernetes.deploy=true
./mvnw clean package -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