此内容没有您所选择的语言版本。
Chapter 4. Using S2I to deploy Quarkus applications on OpenShift
The traditional source-to-image (S2I) method is widely used as the preferred method for deploying applications on Red Hat OpenShift Container Platform. With S2I, you must provide the source code to the build container either through a Git repository or by uploading the source at build time. Use this method to deploy your Quarkus applications in production environments.
Prerequisites
- You have a Quarkus Maven project hosted in a Git repository.
Procedure
- Change to the directory that contains your Quarkus Maven project.
-
Create a hidden directory called
.s2iat the same level as thepom.xmlfile. Create a file called
environmentin the.s2idirectory and add the following content:ARTIFACT_COPY_ARGS=-p -r lib/ *-runner.jar
ARTIFACT_COPY_ARGS=-p -r lib/ *-runner.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Commit and push your changes to the remote Git repository.
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 import the supported OpenShift image, enter the following command:
oc import-image --confirm openjdk/openjdk-11-rhel7 --from=registry.access.redhat.com/openjdk/openjdk-11-rhel7
oc import-image --confirm openjdk/openjdk-11-rhel7 --from=registry.access.redhat.com/openjdk/openjdk-11-rhel7Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you are deploying on IBM Z infrastructure, enter
oc import-image --confirm openj9/openj9-11-rhel8 --from=registry.access.redhat.com/openj9/openj9-11-rhel8.For information about this image, see the Red Hat OpenJDK 11 Java Applications page.
To build the project in OpenShift, enter the following command where
GIT_PATHis the path to the Git repository that hosts your Quarkus project andPROJECT_NAMEis the OpenShift project that you created.oc new-app openjdk-11-rhel7 GIT_PATH --name=PROJECT_NAME
oc new-app openjdk-11-rhel7 GIT_PATH --name=PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you are deploying on IBM Z infrastructure, enter
oc new-app openj9/openj9-11-rhel8 GIT_PATH --name=PROJECT_NAME.This command builds the project, creates the application, and deploys the OpenShift service.
To create an OpenShift route, enter the following command:
oc expose service/PROJECT_NAME
oc expose service/PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow To view the new route, enter the following command where
APPLICATION_NAMEis the name of an application deployed in your OpenShift project:export URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}}')" echo "Application URL: $URL"export URL="http://$(oc get route APPLICATION_NAME -o jsonpath='{.spec.host}}')" echo "Application URL: $URL"Copy 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 - To use your application, enter the URL returned in the preceding command in a web browser.
To deploy an updated version of the project, push any updates to the Git repository then enter the following command:
oc start-build PROJECT_NAME
oc start-build PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow - Refresh your browser page after the build completes to see the changes.
Revised on 2020-12-08 20:07:33 UTC