A logo showing the text blog.marcnuri.com
Español
Home»Java»Kubernetes Client for Java: Fabric8 introduction

Recent Posts

  • Fabric8 Kubernetes Client 7.2 is now available!
  • Connecting to an MCP Server from JavaScript using AI SDK
  • Connecting to an MCP Server from JavaScript using LangChain.js
  • The Future of Developer Tools: Adapting to Machine-Based Developers
  • Connecting to a Model Context Protocol (MCP) Server from Java using LangChain4j

Categories

  • Artificial Intelligence
  • Front-end
  • Go
  • Industry and business
  • Java
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Tools

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • September 2019
  • July 2019
  • March 2019
  • November 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • July 2017
  • January 2017
  • December 2015
  • November 2015
  • December 2014
  • March 2014
  • February 2011
  • November 2008
  • June 2008
  • May 2008
  • April 2008
  • January 2008
  • November 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

Kubernetes Client for Java: Fabric8 introduction

2021-12-01 in Java tagged Kubernetes / Client / Java / Cloud / Fabric8 / OpenShift by Marc Nuri | Last updated: 2025-01-11
Versión en Español

Introduction

The Kubernetes ecosystem for Java developers is flourishing, offering a variety of tools and resources to interact with your cluster. If you need to interact with the Kubernetes API server, there are several client libraries available.

As a RedHatter, I'm the responsible for the maintenance of the Fabric8 Kubernetes Client, a powerful and widely adopted Java library for working with Kubernetes.

The logo of Fabric8 Kubernetes Client
The logo of Fabric8 Kubernetes Client

The Fabric8 Kubernetes Client is one of the oldest and most established Java clients for Kubernetes. Despite the emergence of the official CNCF Java Client, Fabric8 remains highly popular due to its robust feature set, extensibility, and developer-friendly APIs.

Key features of the Fabric8 Kubernetes Client

The Fabric8 Kubernetes Client offers a wide range of features that make it an excellent choice for Java developers working with Kubernetes and sets it apart from its competitors.

  1. Rich DSL: The client offers a Domain Specific Language (DSL) that simplifies interactions with the Kubernetes API.
  2. Extensibility: It supports various extensions, including those for Knative, Tekton, and Istio.
  3. Flexible HTTP Client: Since version 6.0, users can configure the underlying HTTP client, allowing for better integration with existing applications.
  4. Custom Resource Support: The client provides excellent support for working with Custom Resource Definitions (CRDs).
  5. Native Compatibility: It's designed to work seamlessly in native mode, making it an excellent choice for projects using frameworks like Quarkus.

Built-in support for Kubernetes and OpenShift

The Fabric8 Kubernetes Client offers tailored support for both Kubernetes and OpenShift.

ClusterComponent/Artifact
Kuberneteskubernetes-client
OpenShiftopenshift-client

While the kubernetes-client artifact is compatible with any Kubernetes distribution, the openshift-client provides additional capabilities specific to OpenShift.

Extensions for Enhanced Functionality

The Fabric8 Kubernetes Client also supports a growing ecosystem of extensions, enabling seamless integration with tools like Cert Manager, Istio, Tekton, and many more:

ExtensionComponent/Artifact
Cert Managercertmanager-client
Chaos Meshchaosmesh-client
Istioistio-client
Knativeknative-client
Open Cluster Managementopen-cluster-management-client
Open Virtual Networkingopen-cluster-management-client
Tektontekton-client
Vertical Pod Autoscalerverticalpodautoscaler-client
Volcanovolcano-client
Volume Snapshotvolumesnapshot-client

Getting Started with Fabric8 Kubernetes Client

Let's start by setting up the Fabric8 Kubernetes Client in your project.

How do I set up Fabric8 Kubernetes Client in my project?

Adding Fabric8 to your project is straightforward.

Use the following dependency for Maven:

pom.xml
<dependency>
  <groupId>io.fabric8</groupId>
  <artifactId>kubernetes-client</artifactId>
  <version>7.1.0</version>
</dependency>

Or if your project is based on Gradle:

build.gradle
dependencies {
  implementation 'io.fabric8:kubernetes-client:7.1.0'
}

Common Operations with Fabric8 Kubernetes Client

The Fabric8 Java Client should allow you to perform at least the same operations you can execute with Kubectl or the Kubernetes Go client.

In the following sections, you will find a summary of the most common tasks (usually CRUD related) that you can achieve while using the Fabric8 client.

Retrieving a list of resources

The next example returns a list of Pods for the specified namespace:

try (KubernetesClient kc = new KubernetesClientBuilder().build()) {
  kc.pods().inNamespace("my-namespace").list().getItems()
    .forEach(pod ->
      System.out.printf("Pod %s%n", pod.getMetadata().getName()));
}

Retrieving a resource with a given name

The following example retrieves a Pod with the provided name from the specified namespace:

Pod pod = kc.pods().inNamespace("my-namespace").withName("my-pod").get();

Creating a resource

The hereunder example creates a ConfigMap in the specified namespace:

kc.configMaps().inNamespace("my-namespace").resource(
    new ConfigMapBuilder()
      .withNewMetadata().withName("my-configmap").endMetadata()
      .addToData("data-field", "data-value")
      .build()
  ).create();

Editing a resource with a given name

The following example adds an annotation to a Pod with the provided name from the specified namespace:

kc.pods().inNamespace("my-namespace").withName("my-pod")
  .edit(p -> new PodBuilder(p)
    .editMetadata().addToAnnotations("edited", "true").endMetadata().build());

Deleting a named resource

The example below deletes a Pod with the provided name in the specified namespace and waits 10 seconds for the operation to complete:

kc.pods().inNamespace("my-namespace").withName("my-pod").delete();
kc.pods().inNamespace("my-namespace").withName("my-pod")
  .waitUntilCondition(Objects::isNull, 10, TimeUnit.SECONDS);

These examples demonstrate the simplicity and power of Fabric8's fluent DSL. For more examples, explore the official cheatsheet.

Conclusion

The Fabric8 Kubernetes Client is a comprehensive tool for Java developers working with Kubernetes. Its rich features, extensions, and developer-friendly API make it an excellent choice for managing Kubernetes resources programmatically.

Stay tuned for more articles where I’ll dive deeper into advanced operations, integration with tools like the Mock Server, and real-world use cases.

In the meantime, you can explore the following resources:

  • Official GitHub Repository
  • Official Examples Project
  • Fabric8 Kubernetes Client Cheatsheet
Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Post navigation
Build Kubernetes controllers with Fabric8 Kubernetes Client, Quarkus, and JKubeQuarkus: How to change the application port?
© 2007 - 2025 Marc Nuri