A logo showing the text blog.marcnuri.com
Español
Home»Java»Kubernetes Client for Java: How to set up the underlying HTTP client

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: How to set up the underlying HTTP client

2023-09-01 in Java tagged Kubernetes / Client / Java / Cloud / Fabric8 / OpenShift by Marc Nuri | Last updated: 2024-03-21
Versión en Español

Introduction

The Fabric8 Kubernetes Client stands out as one of the most popular Java clients for Kubernetes. If you compare it to other clients, it has an additional rich set of features and performance optimizations that set it apart from other Kubernetes clients.

One remarkable feature introduced in version 6.0 allows you to configure the underlying HTTP client used by the Kubernetes client. This unique capability makes the Fabric8 Client an incredibly flexible choice.

Choosing the right HTTP client is particularly valuable when you want to align your Kubernetes client with the HTTP client already in use by your application. For instance, the Fabric8 Kubernetes Client instance provided by Quarkus defaults to Eclipse Vert.x.

The Fabric8 Kubernetes client offers multiple built-in HTTP client implementations. You will likely find one that fits your needs. Let's explore these options in detail and learn how to configure them.

Available HTTP client implementations

Currently, the Fabric8 Kubernetes Client provides the following HTTP client implementations:

  • OkHttp
  • Vanilla Java JDK HttpClient
  • Eclipse Vert.x
  • Eclipse Jetty

OkHttp is the default HTTP client implementation provided by Fabric8. This has been traditionally the case since the first versions of the client. This is also the main reason why it's still shipped by default and why it's provided as a transitive dependency of the kubernetes-client module.

Whenever we add a dependency to a different HTTP client implementation, this one will take precedence over OkHttp. However, it's recommended that we exclude the kubernetes-httpclient-okhttp dependency to improve our project build performance. Let us now continue by learning how to configure the vanilla JDK HTTP client.

How to configure the vanilla Java JDK HttpClient

Starting from Java 11, the JDK provides a built-in HTTP client. This is extremely convenient because nowadays, most applications need to communicate with external services and applications through HTTP.

From the Java Kubernetes Client perspective, being able to rely on an HTTP client without adding any additional dependencies is a great advantage. When we released version 6.0, we considered shipping the vanilla JDK HTTP client as the default implementation. However, the JDK HTTP client has some issues that weren't fixed until Java 16. You can find more information about this in the module's readme.

In any case, if you're using Java 16 or any of the new LTS versions, you can safely configure the Kubernetes client to use the JDK HTTP client. The following snippet shows how to set up your project's pom.xml file to use the JDK HTTP client:

pom.xml
<project>
  <dependencies>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-client</artifactId>
      <exclusions>
        <exclusion>
          <groupId>io.fabric8</groupId>
          <artifactId>kubernetes-httpclient-okhttp</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-httpclient-jdk</artifactId>
    </dependency>
  </dependencies>
</project>

Or in case you're using Gradle:

build.gradle
dependencies {
  implementation("io.fabric8:kubernetes-client") {
    exclude group: "io.fabric8", module: "kubernetes-httpclient-okhttp"
  }
  implementation("io.fabric8:kubernetes-httpclient-jetty")
}

Let's now continue by learning how to configure the Eclipse Vert.x HTTP client.

How to configure Eclipse Vert.x

Eclipse Vert.x is a toolkit for building reactive applications on the JVM. It also provides a non-blocking HTTP client that can be used to communicate with external services and applications. Since this is one of the most performant clients available, it's a great choice for the Kubernetes client.

The following code snippet shows how to configure the Kubernetes client to use the Vert.x HTTP client:

pom.xml
<project>
  <dependencies>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-client</artifactId>
      <exclusions>
        <exclusion>
          <groupId>io.fabric8</groupId>
          <artifactId>kubernetes-httpclient-okhttp</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-httpclient-vertx</artifactId>
    </dependency>
  </dependencies>
</project>

Or in case you're using Gradle:

build.gradle
dependencies {
  implementation("io.fabric8:kubernetes-client") {
    exclude group: "io.fabric8", module: "kubernetes-httpclient-okhttp"
  }
  implementation("io.fabric8:kubernetes-httpclient-vertx")
}

How to configure Eclipse Jetty

Eclipse Jetty is mainly a Java HTTP server and servlet container. However, Jetty also provides a high-performance HTTP client that can be used to communicate with external services and applications.

Jetty is also a good choice in case your project is using JDK 11 or a more recent version. The following code snippet shows how to configure the Kubernetes client to use the Jetty HTTP client:

pom.xml
<project>
  <dependencies>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-client</artifactId>
      <exclusions>
        <exclusion>
          <groupId>io.fabric8</groupId>
          <artifactId>kubernetes-httpclient-okhttp</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-httpclient-jetty</artifactId>
    </dependency>
  </dependencies>
</project>

Or in case you're using Gradle:

build.gradle
dependencies {
  implementation("io.fabric8:kubernetes-client") {
    exclude group: "io.fabric8", module: "kubernetes-httpclient-okhttp"
  }
  implementation("io.fabric8:kubernetes-httpclient-jetty")
}

As we've learned, the Fabric8 Kubernetes Client provides multiple HTTP client implementations out of the box. Let us now see what to do in case you want to use a different HTTP client.

How can I use XXX HTTP client?

In case the HTTP client you want to use is not provided by the Fabric8 Kubernetes Client, you can still use it by implementing theHttpClient interfaces. Despite this not being a very easy task, it's still possible to do it.

For example, the Armeria folks are already working on an implementation of the HttpClient interface.

Conclusion

In this article, I've shown you how to configure the Fabric8 Kubernetes Client to use different underlying HTTP clients. Being able to choose the HTTP client is a great feature that allows you to use the same HTTP client that your application may already be using.

The Fabric8 Kubernetes Client already provides multiple HTTP client implementations out of the box. We've also learned that you can implement the HttpClient interface in case you want to use a different HTTP client.

The logo of Fabric8 Kubernetes Client
The logo of Fabric8 Kubernetes Client
Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Post navigation
Bash: How to iterate through a list of stringsEclipse JKube 1.14 is now available!
© 2007 - 2025 Marc Nuri