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

Dev Services for Kubernetes

Dev Services for Kubernetesは、開発モードとテスト実行時にKubernetes APIサーバ(と必要なetcd)を自動的に起動します。そのため、手動で起動する必要はありません。アプリケーションは自動的に設定されます。

以下の testcontainers がサポートされています: kindk3s 、apiのみ(デフォルト)

Dev Services for Kubernetesの有効化/無効化

Dev Services for Kubernetesは、以下の場合を除き、自動的に有効化されます。

  • quarkus.kubernetes-client.devservices.enabledfalse に設定されている場合

  • api-server-url が設定されている場合

  • 有効な Kube 設定ファイルが見つかり、 quarkus.kubernetes-client.devservices.override-kubeconfigtrue に設定されていない場合

  • quarkus-test-kubernetes-client の依存関係を含めている場合

Dev Services for Kubernetesはコンテナエンジンに依存しています:サーバを起動するにはDockerまたはPodmanを使用します。 お使いの環境がそのようなコンテナエンジンをサポートしていない場合は、VMやクラウドなどで実行されているKubernetesクラスタを起動する必要があります。この場合、Kube configファイルまたは KubernetesClientBuildConfig クラスで利用可能なさまざまなプロパティを使用して、Kubernetesクラスタへのアクセスを設定できます。

共有クラスター

ほとんどの場合、アプリケーション間でクラスターを共有する必要があります。Dev Services for Kubernetesは、開発モードで実行されている複数のQuarkusアプリケーションが1つのクラスターを共有するための サービス検出 メカニズムを実装しています。

Dev Services for Kubernetesは、コンテナの識別に使用される quarkus-dev-service-kubernetes ラベルを付与してコンテナを起動します。

複数の(共有)クラスターが必要な場合は、 quarkus.kubernetes-client.devservices.service-name 設定プロパティを構成して、クラスター名を指定します。定義された名前のコンテナを検索し、見つからない場合は新しいコンテナを起動します。デフォルトのサービス名は kubernetes です。

共有は、devモードではデフォルトで有効ですが、testモードでは無効です。共有は quarkus.kubernetes-client.devservices.shared=false で無効にできます。

その他開発者向け情報

kubernetesクラスタ上でテストケースを開発したい場合(Dev Serviceによってテストコンテナとして起動)、以下の依存関係をpomファイルに追加します。

pom.xml
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-kubernetes-client</artifactId> </dependency>

そして、Quarkusプロパティを設定してフレーバー、つまりkubeバージョンを選択します。

その後、この チートシート の詳細部分にあるように、多くのkubeタスクを実行できるFabric8 Kubernetes Clientオブジェクトを作成できるようになります。

シンプルなBeanの例
package org.acme; import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.*; import io.fabric8.kubernetes.client.KubernetesClient; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest public class ArgocdExtensionDevModeTest { @Inject private KubernetesClient client; @Test public void testCreatePod() { client.resource(new PodBuilder() .withMetadata(<METADATA_OBJECT>) .withSpec(<SPEC_OBJECT>) .build()) .inNamespace(<USER_NAMESPACE>) .create(); }

クラスタの設定

Dev Services for Kubernetesは、3つの異なるフレーバーのKubernetesクラスタを提供します。各フレーバーは、異なるKubernetes APIバージョンをサポートしています。 フレーバーとバージョンは、 quarkus.kubernetes-client.devservices.flavorquarkus.kubernetes-client.devservices.api-version プロパティを使用して設定することができます。

quarkus.kubernetes-client.devservices.flavor=api-only # k3s or kind quarkus.kubernetes-client.devservices.api-version=1.22

api-only は Kubernetes API サーバー (および必要な etcd) のみを起動します。Pod を起動できるフル機能の Kubernetes クラスターが必要な場合は、 k3s または kind を使用できます。 k3s では、コンテナを privileged mode で起動する必要があります。 kind テスト コンテナは、podman rootless または rootfull の使用をサポートするようになりました。

api-version が設定されていない場合は、与えられた flavor の最新版が使用されます。それ以外の場合は、 定められた flavor がサポート するバージョンと一致しなければなりません。

設定リファレンス

ビルド時に固定される設定プロパティ - その他の設定プロパティは実行時にオーバーライド可能です。

Configuration property

タイプ

デフォルト

If Dev Services for Kubernetes should be used. (default to true) If this is true and kubernetes client is not configured then a kubernetes cluster will be started and will be used.

Environment variable: QUARKUS_KUBERNETES_CLIENT_DEVSERVICES_ENABLED

Show more

ブーリアン

true

The kubernetes api server version to use. If not set, Dev Services for Kubernetes will use the latest supported version of the given flavor. see https://github.com/dajudge/kindcontainer/blob/master/k8s-versions.json

Environment variable: QUARKUS_KUBERNETES_CLIENT_DEVSERVICES_API_VERSION

Show more

string

The flavor to use (kind, k3s or api-only). If not set, Dev Services for Kubernetes will set it to: api-only.

Environment variable: QUARKUS_KUBERNETES_CLIENT_DEVSERVICES_FLAVOR

Show more

kindkind (needs priviledge docker), k3sk3s (needs priviledge docker), api-onlyapi only

By default, if a kubeconfig is found, Dev Services for Kubernetes will not start. Set this to true to override the kubeconfig config.

Environment variable: QUARKUS_KUBERNETES_CLIENT_DEVSERVICES_OVERRIDE_KUBECONFIG

Show more

ブーリアン

false

Indicates if the Kubernetes cluster managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for Kubernetes starts a new container.

The discovery uses the quarkus-dev-service-kubernetes label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_KUBERNETES_CLIENT_DEVSERVICES_SHARED

Show more

ブーリアン

true

The value of the quarkus-dev-service-kubernetes label attached to the started container. This property is used when shared is set to true. In this case, before starting a container, Dev Services for Kubernetes looks for a container with the quarkus-dev-service-kubernetes label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the quarkus-dev-service-kubernetes label set to the specified value.

This property is used when you need multiple shared Kubernetes clusters.

Environment variable: QUARKUS_KUBERNETES_CLIENT_DEVSERVICES_SERVICE_NAME

Show more

string

kubernetes

Environment variables that are passed to the container.

Environment variable: QUARKUS_KUBERNETES_CLIENT_DEVSERVICES_CONTAINER_ENV__ENVIRONMENT_VARIABLE_NAME_

Show more

Map<String,String>

関連コンテンツ