Eclipse JKube introduction: Java tools and plugins for Kubernetes and OpenShift
Introduction
In this post, I will present Eclipse JKube and how you can get started with the project to deploy your Java applications into the Cloud. Eclipse JKube is a collection of plugins and libraries that will help you develop cloud-native Java applications. It includes tools to build container images using Docker, JIB, or S2I build strategies. In addition, JKube provides the means to generate cluster configuration files (YAML) and deploy them into your Kubernetes or OpenShift clusters.
JKube’s history
Eclipse JKube is not an original project but a rebranding and update of the great Fabric8 Maven Plugin. Fabric8 Maven Plugin was part of the larger Fabric8 ecosystem which is now discontinued.
Despite being discontinued, there are still a variety of projects that remain active in the fabric8 ecosystem.
Regarding JKube, in November 2019, the project was donated to and accepted by the Eclipse Foundation. Development efforts have continued under this new name and the 1.0.0 release was finally made generally available (GA) in September 2020.
JKube components
As of now, JKube provides 5 different components:
- JKube Kit: Contains the core logic of the library and is used by the rest of the components (plugins).
- Kubernetes Maven Plugin: Specifically designed to target vanilla Kubernetes clusters. Builds container images using Docker or JIB. Generates standard Kubernetes configuration descriptors.
- OpenShift Maven Plugin: Built on top of the Kubernetes Maven Plugin, provides OpenShift specific features. Builds container images using S2I. Generates OpenShift specific configuration descriptors.
- Kubernetes Gradle Plugin: Provides the same features as the Kubernetes Maven Plugin but for Gradle projects.
- OpenShift Gradle Plugin: Provides the same features as the OpenShift Maven Plugin but for Gradle projects.
Getting started
The fastest way for you to get started with JKube is by using one of the provided Maven Plugins. Making your application Kubernetes friendly is as simple as adding the plugin to the build section of your project:
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>org.eclipse.jkube</groupId>
<artifactId>kubernetes-maven-plugin</artifactId>
<version>1.17.0</version>
</plugin>
</plugins>
<!-- ... -->
</build>
Or in case you are targeting an OpenShift cluster:
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>org.eclipse.jkube</groupId>
<artifactId>openshift-maven-plugin</artifactId>
<version>1.17.0</version>
</plugin>
</plugins>
<!-- ... -->
</build>
If your application is based on one of the supported frameworks (Spring, Quarkus, Vert.x, OpenLiberty, etc.), then this is all the configuration you’ll need. You can also check the official quickstart section on JKube’s main website to find an example that suits your specific needs.
Building the container image
Once you’ve compiled and packaged your application by running the mvn clean package
command,
it’s time to build the container image.
If you are using Minikube as a target cluster, you can share your cluster’s Docker registry by running eval $(minikube docker-env)
.
This way you won’t need to push your image to a remote shared registry.
You can instruct JKube to build a Docker image for your Maven project by running the following command:
mvn k8s:build
Pushing the image to a container registry
This step won’t be necessary if you are using Minikube and you shared your cluster’s Docker daemon. You won’t need to run this step either if you are using the OpenShift Maven Plugin.
If however, you need to push your image, you’ll most probably need to configure your resulting image name. You can do so very easily using a Maven property:
<properties>
<!-- ... -->
<jkube.generator.name>your-docker-hub-user/image-name:latest</jkube.generator.name>
</properties>
You can now run the Maven goal to push your image:
mvn k8s:push
Generating configuration resources
JKube also provides a way to infer your project's requirements and generate cluster configuration manifests (YAML files) for your application.
If you are using one of the supported frameworks, all you’ll have to do is run:
mvn k8s:resource
Deploying your application
Finally, you can deploy the generated configuration files to your cluster. Eclipse JKube internally
uses the Fabric8 Kubernetes Client to
access your cluster by reading your .kube/config
.
Unless you want to target a different cluster, you won’t need to provide any specific configuration either.
mvn k8s:apply
If everything goes well, your application will be available on the cluster.
If you are using OpenShift, JKube will even create a Route
for you.
Your application should be publicly available under the preconfigured route.
Cleaning up
In case anything went wrong, or simply to delete your application from the cluster, you can run the following command:
mvn k8s:undeploy
Additional Maven goals
JKube also provides additional goals to simplify your life as a developer:
k8s:log
: Tails the log of the deployed application.k8s:debug
: Enables debugging for your Java application in the cluster.k8s:watch
: Monitors your project workspace for changes to automatically redeploy your application.- Many more…
EclipseCon 2020
At EclipseCon 2020, I gave an introductory talk to Eclipse JKube at EclipseCon 2020. The video below is the recording of the session where I explain in detail what we've covered in this article:
The EclipseCon presentation includes two live demos.
Conclusion
In this article, I've introduced you to Eclipse JKube and how to get started. I've also shown you how to set up your project and the main Maven goals provided by JKube’s plugins.
If you want to learn more about Eclipse JKube, visit the project's website and documentation. Don't forget to follow jkubeio on Twitter to get the latest updates and news about the project.