此内容没有您所选择的语言版本。
Chapter 3. Using the Quarkus OpenShift extension to deploy Quarkus applications on OpenShift
The traditional source-to-image (S2I) source workflow generates the deployable artifacts of your application inside OpenShift. The Quarkus OpenShift extension uses the S2I binary workflow to provide a more streamlined deployment process. Instead of building from the source, the extension uploads the JAR files from the local file system. As a result, the build process is up to ten times faster than the traditional S2I method. You can use the Quarkus OpenShift extension when developing locally as well as from a build server or continuous integration (CI) system to perform repeatable builds from source.
Use the Quarkus OpenShift extension for development and testing purposes only. For production environments, consider using the traditional S2I method described in Chapter 4, Using S2I to deploy Quarkus applications on OpenShift.
Procedure
- Change to the directory that contains your Quarkus Maven project.
To add the OpenShift extension to an existing project, enter the following command:
./mvnw quarkus:add-extension -Dextensions="openshift"
./mvnw quarkus:add-extension -Dextensions="openshift"Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou can include the
-Dextensions="openshift"argument to add the Quarkus OpenShift extension when you create a new project.When you add the OpenShift extension, the script adds the following dependency to the
pom.xmlfile:<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using an untrusted certificate, add the following line to the
src/main/resources/application.propertiesfile:quarkus.kubernetes-client.trust-certs=true
quarkus.kubernetes-client.trust-certs=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow To direct OpenShift to use the Open JDK 11 Red Hat Enterprise Linux 7 image, add the following line to the
application.propertiesfile:quarkus.s2i.base-jvm-image=registry.access.redhat.com/openjdk/openjdk-11-rhel7
quarkus.s2i.base-jvm-image=registry.access.redhat.com/openjdk/openjdk-11-rhel7Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you are deploying on IBM Z infrastructure, add
quarkus.s2i.base-jvm-image=registry.access.redhat.com/openj9/openj9-11-rhel8to theapplication.propertiesfile.To create an OpenShift route, add the following line to the
application.propertiesfile:quarkus.openshift.expose=true
quarkus.openshift.expose=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Save the changes to the
application.propertiesfile. Log in to the OpenShift CLI (oc):
oc login
oc loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow To create a new OpenShift project, enter the following command where
PROJECT_NAMEis the name of your new project:oc new-project PROJECT_NAME
oc new-project PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow To deploy your project to OpenShift, enter the following command in your Quarkus Maven project directory:
./mvnw clean package -Dquarkus.kubernetes.deploy=true
./mvnw clean package -Dquarkus.kubernetes.deploy=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow To display the names and routes of all deployed applications in the OpenShift project, enter the following command:
oc get route
oc get routeCopy to Clipboard Copied! Toggle word wrap Toggle overflow To view the full URL to the application, where
APPLICATION_NAMEis the name of an application deployed in your OpenShift project, enter the following command:export URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}')" echo "Application URL: $URL" curl $URL/helloexport URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}')" echo "Application URL: $URL" curl $URL/helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow To create an HTTP request on the route’s
helloendpoint, enter the following command:curl $URL/hello
curl $URL/helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow