이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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_HOME environment 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-openshift extension.
  • You have access to a OpenShift Container Platform cluster and the latest compatible version of the oc CLI tool installed.
  • You are working in the correct OpenShift project namespace.

3.2. Procedure

  1. Set the Docker build strategy in your application.properties configuration file:

    quarkus.openshift.build-strategy=docker
    Copy to Clipboard Toggle word wrap
  2. Optional: Set the following properties in the application.properties file, based on your environment:

    • If you are using an untrusted certificate, enable certificate trust for the KubernetesClient:

      quarkus.kubernetes-client.trust-certs=true
      Copy to Clipboard Toggle word wrap
    • To expose the service and create an OpenShift Container Platform route, set the following property:

      quarkus.openshift.route.expose=true
      Copy to Clipboard Toggle word wrap
    • To use a custom Dockerfile instead of the pregenerated Dockerfiles, set the path to your Dockerfile:

      quarkus.openshift.jvm-dockerfile=<path_to_your_dockerfile>
      Copy to Clipboard Toggle word wrap

      For example, to specify a custom Dockerfile named Dockerfile.custom-jvm:

      quarkus.openshift.jvm-dockerfile=src/main/resources/Dockerfile.custom-jvm
      Copy to Clipboard Toggle word wrap
  3. Package and deploy your application to the current OpenShift Container Platform project:

    ./mvnw clean package -Dquarkus.openshift.deploy=true
    Copy to Clipboard Toggle word wrap

3.3. Verification

The following verification steps use the openshift-helloworld example application.

  1. Display the list of pods associated with your current OpenShift project:

    oc get pods
    Copy to Clipboard Toggle word wrap
    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
    Copy to Clipboard Toggle word wrap
  2. To get the log output for your application’s pod, use the oc logs -f command with its name. The following example uses the openshift-helloworld-1-gzzrx pod name, which corresponds to the latest pod prefixed with the name of your application:

    oc logs -f openshift-helloworld-1-gzzrx
    Copy to Clipboard Toggle word wrap
    Starting the Java application using /opt/jboss/container/java/run/run-java.sh ...
    INFO exec -a "java" java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -XX:MaxRAMPercentage=50.0 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -cp "." -jar /deployments/quarkus-run.jar
    __  ____  __  _____   ___  __ ____  ______
    --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
    -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
    --\___\_\____/_/ |_/_/|_/_/|_|\____/___/
    2024-09-17 10:23:25,254 INFO  [io.quarkus] (main) getting-started 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.27.0.redhat-00002) started in 0.653s. Listening on: http://0.0.0.0:8080
    2024-09-17 10:23:25,281 INFO  [io.quarkus] (main) Profile prod activated.
    2024-09-17 10:23:25,281 INFO  [io.quarkus] (main) Installed features: [cdi, kubernetes, rest, smallrye-context-propagation, vertx]
    Copy to Clipboard Toggle word wrap
  3. Get a list of services:

    oc get svc
    Copy to Clipboard Toggle word wrap
    NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                               AGE
    openshift-helloworld   ClusterIP   172.30.64.57     <none>        80/TCP                                14m
    Copy to Clipboard Toggle word wrap
  4. 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=true property in the application.properties file before building the application.

    oc get routes
    Copy to Clipboard Toggle word wrap
    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
    Copy to Clipboard Toggle word wrap
    Note

    Be 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 curl and the complete URL output from oc 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.

3.4. References

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat