Kubernetes client
This page details Kubernetes client.
Dependency
<dependency>
<groupId>io.yupiik.fusion</groupId>
<artifactId>fusion-kubernetes-client</artifactId>
<version>${fusion.version}</version>
</dependency>
Usage
The KubernetesClient implements java.net.http.HttpClient. It is typically used from an operator or a cloud native application to call the Kubernetes API using a plain and very light HTTP client from the JVM.
|
TIP
|
you can combine it with the enhanced HTTP client configuring it in the |
final var conf = new KubernetesClientConfiguration()
.setClientWrapper(client -> new ExtendedHttpClient(new ExtendedHttpClientConfiguration()
.setDelegate(client)));
final var k8s = new KubernetesClient(conf);
// now call any API you need:
final var response = k8s.send(
HttpRequest.newBuilder()
.GET()
.uri(URI.create(
"https://kubernetes.api/api/v1/namespaces/" + k8s.namespace().orElse("default") + "/configmaps?" +
"includeUninitialized=false&" +
"limit=1000&" +
"timeoutSeconds=600")
.header("Accept", "application/json")
.build(),
HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
// handle the response
|
IMPORTANT
|
as you can see, there is no need to pass the token to the request, it is done under the hood by the |
Configuration
KubernetesClientConfiguration reads the master URL from the KUBERNETES_SERVICE_HOST/KUBERNETES_SERVICE_PORT environment variables when running in cluster and supports:
-
token path or evaluator (
/var/run/secrets/kubernetes.io/serviceaccount/token), -
client/server certificates and private key,
-
skipTls, -
a
kubeconfigfor out-of-cluster usage, -
a client customizer/wrapper to decorate the underlying
HttpClient.