The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.
このページを編集

S2Iを使用したQuarkusアプリケーションのOpenShiftへのデプロイ

Quarkus のアプリケーションを OpenShift にデプロイするには、Source-to-Image (S2I) メソッドを使用します。S2Iでは、Gitリポジトリを通して、あるいはビルド時にソースコードをアップロードして、ビルドコンテナにソースコードを提供する必要があります。

You can deploy Quarkus applications to OpenShift with Java 17, 21, or 25 versions.

前提条件

  • You have a Quarkus application built with Java 17, 21, or 25.

  • オプション:Quarkusプロジェクトに quarkus-openshift エクステンションが含まれていること

  • 正しい OpenShift プロジェクトの名前空間で作業していること

  • プロジェクトがGitリポジトリにホストされていること

手順

  1. Open the pom.xml file, and set the Java version.

    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>

    where ${java.version} is 17, 21, or 25.

  2. Package your application, by entering the following command:

    ./mvnw clean package
  3. pom.xml ファイルと同じ階層に .s2i というディレクトリを作成します。

  4. .s2i ディレクトリに environment というファイルを作成し、以下の内容を追加します:

    MAVEN_S2I_ARTIFACT_DIRS=target/quarkus-app
    S2I_SOURCE_DEPLOYMENTS_FILTER=app lib quarkus quarkus-run.jar
    JAVA_OPTIONS=-Dquarkus.http.host=0.0.0.0
    AB_JOLOKIA_OFF=true
    JAVA_APP_JAR=/deployments/quarkus-run.jar
  5. 変更をコミットして、リモートの Git リポジトリにプッシュします。

  6. Import the supported OpenShift image.

    Java 17:

    oc import-image ubi9/openjdk-17 --from=registry.access.redhat.com/ubi9/openjdk-17 --confirm

    Java 21:

    oc import-image ubi9/openjdk-21 --from=registry.access.redhat.com/ubi9/openjdk-21 --confirm

    Java 25:

    oc import-image ubi9/openjdk-25 --from=registry.access.redhat.com/ubi9/openjdk-25 --confirm
    • OpenShiftのイメージレジストリを使用し、同じプロジェクト内のイメージストリームからプルしている場合、ポッドのサービスアカウントはすでに正しいパーミッションを持っている必要があります。

    • 他の OpenShift プロジェクトや保護されたレジストリからイメージを引っ張ってくる場合は、追加の設定手順が必要になるかもしれません。

      詳細は、 Red Hat Openshift Container Platform のドキュメントを参照してください。

    • If you are deploying on IBM Z infrastructure, enter oc import-image ubi9/openjdk-21 --from=registry.redhat.io/ubi9/openjdk-21 --confirm instead. For information about this image, see OpenJDK 21 runtime image on UBI9.

  7. Build the project, create the application, and deploy the OpenShift service.

    Java 17:

    oc new-app registry.access.redhat.com/ubi9/openjdk-17~<git_path> --name=<project_name>

    Java 21:

    oc new-app registry.access.redhat.com/ubi9/openjdk-21~<git_path> --name=<project_name>

    Java 25:

    oc new-app registry.access.redhat.com/ubi9/openjdk-25~<git_path> --name=<project_name>
    • Replace <git_path> with the path of the Git repository that hosts your Quarkus project. For example, for Java 21: oc new-app registry.access.redhat.com/ubi9/openjdk-21~https://github.com/johndoe/code-with-quarkus.git --name=code-with-quarkus.

      Git リポジトリに SSH 鍵を設定していない場合は、Git のパスを指定する際に SSH URL ではなく HTTPS URL を使ってください。

    • <project_name> をアプリケーション名に置き換えてください。

      IBM Zインフラストラクチャにデプロイする場合は、代わりに oc new-app ubi9/openjdk-21~<git_path> --name=<project_name> を入力してください。

  8. プロジェクトの更新版をデプロイするには、変更をGitリポジトリにプッシュしてから実行します:

    oc start-build <project_name>
  9. アプリケーションへのルートを公開するには、以下のコマンドを実行します:

    oc expose svc <project_name>

検証

  1. 現在の OpenShift プロジェクトに関連するポッドを一覧表示します:

    oc get pods
  2. アプリケーションのポッドのログ出力を取得するには、次のコマンドを実行します。 <pod_name> を最新のポッドの名前に置き換え、その前にアプリケーション名を付けます:

    oc logs -f <pod_name>

関連コンテンツ