The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

Dev Services para Kubernetes

Dev Services for Kubernetes automatically starts a Kubernetes API server (plus the required etcd) in dev mode and when running tests. So you don’t have to start it manually. The application is configured automatically.

The following testcontainers are supported: kind, k3s or api only(default)

Ativar/desativar Dev Services para Kubernetes

O Dev Services para Kubernetes é ativado automaticamente, a menos que:

  • quarkus.kubernetes-client.devservices.enabled esteja definido como false

  • a URL api-server-url esteja configurada

  • um arquivo de configuração Kube válido seja encontrado e quarkus.kubernetes-client.devservices.override-kubeconfig não está definido como true

  • você inclua a dependência quarkus-test-kubernetes-client

Dev Services for Kubernetes relies on a container engine: Docker or Podman to start the server. If your environment does not support such a container engine, you will have to start a Kubernetes cluster running in a VM, in the cloud, etc. In this case, you can configure the Kubernetes cluster access using either a Kube config file or the various properties available in the KubernetesClientBuildConfig class.

Cluster compartilhado

Na maioria das vezes, você precisa compartilhar o cluster entre as aplicações. O Dev Services para Kubernetes implementa um mecanismo de descoberta de serviços para que suas várias aplicações Quarkus em execução no modo de desenvolvimento compartilhem um único cluster.

O Dev Services para Kubernetes inicia o contêiner com o rótulo quarkus-dev-service-kubernetes que é utilizado para identificar o contêiner.

Se precisar de vários clusters (compartilhados), você pode configurar a propriedade de configuração quarkus.kubernetes-client.devservices.service-name e indicar o nome do cluster. Ele procura um contêiner com o nome definido ou inicia um novo contêiner se nenhum for encontrado. O nome padrão do serviço é kubernetes.

O compartilhamento é ativado por padrão no modo de desenvolvimento, mas desativado no modo de teste. Você pode desativar o compartilhamento com quarkus.kubernetes-client.devservices.shared=false .

What else for the developers

If you would like to develop test cases running top of the kubernetes cluster (launched as test container by the Dev Service), then add the following dependencies to your pom file

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

and set the Quarkus properties to select the flavor, or kube version.

Then you will be able to create a Fabric8 Kubernetes Client object able to perform many kube tasks as detailed part of this cheat sheet.

Simple Bean Example
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();
    }

Configurando o cluster

O Dev Services para Kubernetes oferece três tipos diferentes de cluster do Kubernetes. Cada tipo oferece suporte a diferentes versões da API do Kubernetes. Você pode configurar o tipo e a versão usando as propriedades quarkus.kubernetes-client.devservices.flavor e quarkus.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 only starts a Kubernetes API Server (plus the required etcd). If you need a fully-featured Kubernetes cluster that can spin up Pods, you can use k3s or kind. k3s requires to start the container with privileged mode. The kind test container supports now to use podman rootless or rootfull.

Se a api-version não estiver definida, a versão mais recente para o tipo fornecido será usada. Caso contrário, a versão deve corresponder a uma versão suportada pelo tipo fornecido.

Configuration reference

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Tipo

Padrão

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

boolean

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

boolean

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

boolean

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>

Conteúdo Relacionado