|
| 1 | +//// |
| 2 | +This guide is maintained in the main Quarkus repository |
| 3 | +and pull requests should be submitted there: |
| 4 | +https://github.com/quarkusio/quarkus/tree/main/docs/src/main/asciidoc |
| 5 | +//// |
| 6 | +[id="deploying-to-openshift-docker-howto"] |
| 7 | += Deploy {project-name} Java applications to {openshift} by using a Docker build strategy |
| 8 | +include::_attributes.adoc[] |
| 9 | +:diataxis-type: howto |
| 10 | +:categories: cloud, native |
| 11 | +:summary: This guide describes how to build and deploy a Quarkus application on {openshift} by using the Docker build strategy. |
| 12 | +:topics: devops,kubernetes,openshift,cloud,deployment |
| 13 | +:extensions: io.quarkus:quarkus-openshift |
| 14 | + |
| 15 | +As an application developer, you can deploy your applications to {openshift} by using the Docker build strategy as a deployment option. |
| 16 | + |
| 17 | +This stategy builds the artifacts outside the {openshift} cluster, locally or in a CI environment, and provides them to the {openshift} build system together with a Dockerfile. |
| 18 | +The artifacts include JAR files or a native executable. |
| 19 | +The {openshift} cluster builds the container and provides it as an image stream. |
| 20 | + |
| 21 | +This functionality is provided by the `quarkus-openshift` extension. |
| 22 | +If you want to use a custom Dockerfile, add the file to the `src/main/docker` directory or any location inside the module. |
| 23 | +Additionally, set the path to your Dockerfile by using the `quarkus.openshift.jvm-dockerfile` property. |
| 24 | + |
| 25 | +== Prerequisites |
| 26 | + |
| 27 | +* You have OpenJDK {jdk-version-all} installed. |
| 28 | +* You have set the `JAVA_HOME` environment variable to the location of the Java SDK. |
| 29 | +* You have Apache Maven {maven-version} installed. |
| 30 | +* You have a Quarkus project that includes the `quarkus-openshift` extension. |
| 31 | +* You have access to a {openshift} cluster and the latest compatible version of the `oc` CLI tool installed. |
| 32 | +* You are working in the correct OpenShift project namespace. |
| 33 | + |
| 34 | +== Procedure |
| 35 | + |
| 36 | +. Set the Docker build strategy in your `application.properties` configuration file: |
| 37 | ++ |
| 38 | +[source, properties] |
| 39 | +---- |
| 40 | +quarkus.openshift.build-strategy=docker |
| 41 | +---- |
| 42 | +. Optional: Set the following properties in the `application.properties` file, based on your environment: |
| 43 | +** If you are using an untrusted certificate, enable certificate trust for the `KubernetesClient`: |
| 44 | ++ |
| 45 | +[source,properties] |
| 46 | +---- |
| 47 | +quarkus.kubernetes-client.trust-certs=true |
| 48 | +---- |
| 49 | +** To expose the service and create an {openshift} route, set the following property: |
| 50 | ++ |
| 51 | +[source,properties] |
| 52 | +---- |
| 53 | +quarkus.openshift.route.expose=true |
| 54 | +---- |
| 55 | +** To use a custom Dockerfile instead of the pregenerated Dockerfiles, set the path to your Dockerfile: |
| 56 | ++ |
| 57 | +[source,properties,subs="attributes+,+quotes"] |
| 58 | +---- |
| 59 | +quarkus.openshift.jvm-dockerfile=<path_to_your_dockerfile> |
| 60 | +---- |
| 61 | ++ |
| 62 | +For example, to specify a custom Dockerfile named `Dockerfile.custom-jvm`: |
| 63 | ++ |
| 64 | +[source,properties] |
| 65 | +---- |
| 66 | +quarkus.openshift.jvm-dockerfile=src/main/resources/Dockerfile.custom-jvm |
| 67 | +---- |
| 68 | + |
| 69 | +. Package and deploy your application to the current {openshift} project: |
| 70 | ++ |
| 71 | +[source,shell,subs="attributes+,+quotes"] |
| 72 | +---- |
| 73 | +./mvnw clean package -Dquarkus.openshift.deploy=true |
| 74 | +---- |
| 75 | + |
| 76 | +== Verification |
| 77 | + |
| 78 | +The following verification steps use the `openshift-helloworld` example application. |
| 79 | + |
| 80 | +. Display the list of pods associated with your current OpenShift project: |
| 81 | ++ |
| 82 | +[source,shell,subs="+quotes",options="nowrap"] |
| 83 | +---- |
| 84 | +oc get pods |
| 85 | +---- |
| 86 | ++ |
| 87 | +[source,shell,subs="+quotes",options="nowrap"] |
| 88 | +---- |
| 89 | +NAME READY STATUS RESTARTS AGE |
| 90 | +openshift-helloworld-1-build 0/1 Completed 0 11m |
| 91 | +openshift-helloworld-1-deploy 0/1 Completed 0 10m |
| 92 | +openshift-helloworld-1-gzzrx 1/1 Running 0 10m |
| 93 | +---- |
| 94 | + |
| 95 | +. To get the log output for your application's pod, use the `oc logs -f` command with its name. |
| 96 | +The following example uses the `openshift-helloworld-1-gzzrx` pod name, which corresponds to the latest pod prefixed with the name of your application: |
| 97 | ++ |
| 98 | +[source,shell,subs="+quotes",options="nowrap"] |
| 99 | +---- |
| 100 | +oc logs -f _openshift-helloworld-1-gzzrx_ |
| 101 | +---- |
| 102 | ++ |
| 103 | +[source,shell,subs=attributes+] |
| 104 | +---- |
| 105 | +Starting the Java application using /opt/jboss/container/java/run/run-java.sh ... |
| 106 | +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 |
| 107 | +__ ____ __ _____ ___ __ ____ ______ |
| 108 | +--/ __ \/ / / / _ | / _ \/ //_/ / / / __/ |
| 109 | +-/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \ |
| 110 | +--\___\_\____/_/ |_/_/|_/_/|_|\____/___/ |
| 111 | +2024-09-17 10:23:25,254 INFO [io.quarkus] (main) getting-started 1.0.0-SNAPSHOT on JVM (powered by Quarkus {QuarkusCore}) started in 0.653s. Listening on: http://0.0.0.0:8080 |
| 112 | +2024-09-17 10:23:25,281 INFO [io.quarkus] (main) Profile prod activated. |
| 113 | +2024-09-17 10:23:25,281 INFO [io.quarkus] (main) Installed features: [cdi, kubernetes, rest, smallrye-context-propagation, vertx] |
| 114 | +---- |
| 115 | + |
| 116 | +. Get a list of services: |
| 117 | ++ |
| 118 | +[source,shell,subs="+quotes",options="nowrap"] |
| 119 | +---- |
| 120 | +oc get svc |
| 121 | +---- |
| 122 | ++ |
| 123 | +[source,shell,subs="+quotes",options="nowrap"] |
| 124 | +---- |
| 125 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 126 | +openshift-helloworld ClusterIP 172.30.64.57 <none> 80/TCP 14m |
| 127 | +---- |
| 128 | + |
| 129 | +. Get a URL to test your application. |
| 130 | +To do so, ensure you have exposed an {openshift} route by setting the `quarkus.openshift.route.expose=true` property in the `application.properties` file before building the application. |
| 131 | ++ |
| 132 | +[source,shell,subs="+quotes",options="nowrap"] |
| 133 | +---- |
| 134 | +oc get routes |
| 135 | +---- |
| 136 | ++ |
| 137 | +[source,shell,subs="+quotes",options="nowrap"] |
| 138 | +---- |
| 139 | +NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD |
| 140 | +openshift-helloworld openshift-helloworld-username-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com openshift-helloworld http None |
| 141 | +---- |
| 142 | ++ |
| 143 | +[NOTE] |
| 144 | +==== |
| 145 | +Be aware that the route is now listening on port 80 and is no longer on port 8080. |
| 146 | +==== |
| 147 | ++ |
| 148 | +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". |
| 149 | ++ |
| 150 | +For example: `curl \http://openshift-helloworld-username-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com`. |
| 151 | + |
| 152 | +== References |
| 153 | + |
| 154 | +* xref:deploying-to-openshift.adoc[Deploying {project-name} applications to {openshift}] |
| 155 | + |
| 156 | + |
0 commit comments