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

ネイティブ実行可能ファイルにコンパイルされた Quarkus アプリケーションのデプロイ

You can deploy your Quarkus applications compiled to native executables to OpenShift by using the Docker build strategy.

You must create a native executable for your application that targets a supported operating system and matches the architecture. This means, if you are building on Windows, you create a native Linux executable by using a container runtime, for example, Docker or Podman.

Your Quarkus project includes pregenerated Dockerfiles with instructions. If you want to use a custom Dockerfile, add the file to the src/main/docker directory or any location inside the module.

Additionally, if you want to have multiple Dockerfiles and switch between them, set the path to your preferred Dockerfile by using the quarkus.openshift.native-dockerfile property.

このガイドでは、Maven を使用した Quarkus プロジェクトを例として使用して、この戦略について説明します。

前提条件

  • サポートされているオペレーティングシステム、または Podman や Docker など、Open Container Initiative (OCI) 互換のコンテナーランタイム。

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

  • OpenShift クラスタにアクセスでき、 oc CLIツールの最新互換バージョンがインストールされていること

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

手順

  1. application.properties 設定ファイルで Docker ビルドストラテジーを設定します:

    quarkus.openshift.build-strategy=docker
  2. コンテナーベースのネイティブビルドを有効にする:

    quarkus.native.container-build=true
  3. オプション: 環境に基づいて、 application.properties ファイルに以下のプロパティーを設定します:

    • 信頼されていない証明書を使用している場合は、 KubernetesClient の証明書の信頼を有効にします:

      quarkus.kubernetes-client.trust-certs=true
    • サービスを公開し、 OpenShift ルートを作成するには、以下のプロパティを設定します:

      quarkus.openshift.route.expose=true
    • 事前に生成された Dockerfile の代わりにカスタム Dockerfile を使用するには、カスタム Dockerfile へのパスを設定します:

      quarkus.openshift.native-dockerfile=<path_to_your_dockerfile>

      例えば、Dockerfile.custom-native という名前のカスタム Dockerfile を指定するには:

      quarkus.openshift.native-dockerfile=src/main/docker/Dockerfile.custom-native
    • コンテナーエンジンを指定する:

      • Podman を使用してネイティブ実行可能ファイルをビルドするには:

        quarkus.native.container-runtime=podman
      • Docker を使用してネイティブ実行可能ファイルをビルドするには:

        quarkus.native.container-runtime=docker
  4. 最後に、ネイティブ実行可能ファイルをビルドし、アプリケーションをパッケージ化して OpenShift にデプロイします:

    ./mvnw clean package -Pnative -Dquarkus.openshift.deploy=true

検証

  1. イメージストリームとサービスリソースが作成され、アプリケーションがデプロイされていることを確認します。OpenShift Web コンソールまたは以下の OpenShift コマンドラインインターフェース (CLI) コマンドを使用します:

    oc get is (1)
    oc get pods (2)
    oc get svc (3)
    1 作成されたイメージストリームを一覧表示します。
    2 現在の OpenShift プロジェクトに関連するポッドを一覧表示します。
    3 Kubernetesサービスをリストアップします。
  1. アプリケーションの Pod のログ出力を取得するには、<pod_name> (アプリケーション名の前に付加された最新の Pod の名前) を指定して次のコマンドを実行します:

    oc logs -f <pod_name>

関連コンテンツ