이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 3. Deploying Red Hat build of Quarkus Java applications to OpenShift Container Platform by using a Docker build strategy
As an application developer, you can deploy your applications to OpenShift Container Platform by using the Docker build strategy as a deployment option.
This stategy builds the artifacts outside the OpenShift Container Platform cluster, locally or in a CI environment, and provides them to the OpenShift Container Platform build system together with a Dockerfile. The artifacts include JAR files or a native executable. The OpenShift Container Platform cluster builds the container and provides it as an image stream.
This functionality is provided by the quarkus-openshift extension. If you want to use a custom Dockerfile, add the file to the src/main/docker directory or any location inside the module. Additionally, set the path to your Dockerfile by using the quarkus.openshift.jvm-dockerfile property.
3.1. Prerequisites 링크 복사링크가 클립보드에 복사되었습니다!
- You have OpenJDK 17 or 21 installed.
-
You have set the
JAVA_HOMEenvironment variable to the location of the Java SDK. - You have Apache Maven 3.8.6 or later installed.
-
You have a Quarkus project that includes the
quarkus-openshiftextension. -
You have access to a OpenShift Container Platform cluster and the latest compatible version of the
ocCLI tool installed. - You are working in the correct OpenShift project namespace.
3.2. Procedure 링크 복사링크가 클립보드에 복사되었습니다!
Set the Docker build strategy in your
application.propertiesconfiguration file:quarkus.openshift.build-strategy=docker
quarkus.openshift.build-strategy=dockerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Set the following properties in the
application.propertiesfile, based on your environment:If you are using an untrusted certificate, enable certificate trust for the
KubernetesClient:quarkus.kubernetes-client.trust-certs=true
quarkus.kubernetes-client.trust-certs=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow To expose the service and create an OpenShift Container Platform route, set the following property:
quarkus.openshift.route.expose=true
quarkus.openshift.route.expose=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow To use a custom Dockerfile instead of the pregenerated Dockerfiles, set the path to your 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 For example, to specify a custom Dockerfile named
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 application to the current OpenShift Container Platform project:
./mvnw clean package -Dquarkus.openshift.deploy=true
./mvnw clean package -Dquarkus.openshift.deploy=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.3. Verification 링크 복사링크가 클립보드에 복사되었습니다!
The following verification steps use the openshift-helloworld example application.
Display the list of pods associated with your current OpenShift project:
oc get pods
oc get podsCopy to Clipboard Copied! Toggle word wrap Toggle overflow NAME READY STATUS RESTARTS AGE openshift-helloworld-1-build 0/1 Completed 0 11m openshift-helloworld-1-deploy 0/1 Completed 0 10m openshift-helloworld-1-gzzrx 1/1 Running 0 10m
NAME READY STATUS RESTARTS AGE openshift-helloworld-1-build 0/1 Completed 0 11m openshift-helloworld-1-deploy 0/1 Completed 0 10m openshift-helloworld-1-gzzrx 1/1 Running 0 10mCopy to Clipboard Copied! Toggle word wrap Toggle overflow To get the log output for your application’s pod, use the
oc logs -fcommand with its name. The following example uses theopenshift-helloworld-1-gzzrxpod name, which corresponds to the latest pod prefixed with the name of your application:oc logs -f openshift-helloworld-1-gzzrx
oc logs -f openshift-helloworld-1-gzzrxCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get a list of services:
oc get svc
oc get svcCopy to Clipboard Copied! Toggle word wrap Toggle overflow NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE openshift-helloworld ClusterIP 172.30.64.57 <none> 80/TCP 14m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE openshift-helloworld ClusterIP 172.30.64.57 <none> 80/TCP 14mCopy to Clipboard Copied! Toggle word wrap Toggle overflow Get a URL to test your application. To do so, ensure you have exposed an OpenShift Container Platform route by setting the
quarkus.openshift.route.expose=trueproperty in theapplication.propertiesfile before building the application.oc get routes
oc get routesCopy to Clipboard Copied! Toggle word wrap Toggle overflow NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD openshift-helloworld openshift-helloworld-username-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com openshift-helloworld http None
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD openshift-helloworld openshift-helloworld-username-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com openshift-helloworld http NoneCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteBe aware that the route is now listening on port 80 and is no longer on port 8080.
You can test the application demonstrated in this example with a web browser or a terminal by using
curland the complete URL output fromoc get routes, that is,http://openshift-helloworld-username-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com.For example:
curl http://openshift-helloworld-username-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com.