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.
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 GA in September 2020.
As of now, JKube provides 3 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.
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:
1<build> 2 <plugins> 3 <!-- ... --> 4 <plugin> 5 <groupId>org.eclipse.jkube</groupId> 6 <artifactId>kubernetes-maven-plugin</artifactId> 7 <version>1.4.0</version> 8 </plugin> 9 </plugins> 10 <!-- ... --> 11</build>
Or in case you are targeting an OpenShift cluster:
1<build> 2 <plugins> 3 <!-- ... --> 4 <plugin> 5 <groupId>org.eclipse.jkube</groupId> 6 <artifactId>openshift-maven-plugin</artifactId> 7 <version>1.4.0</version> 8 </plugin> 9 </plugins> 10 <!-- ... --> 11</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 quickstart section on JKube’s main website to find an example that suits your specific needs.
Once you’ve compiled and packaged your application (
mvn clean package) it’s time to build the container image.
Note: If you are using Minikube as a target cluster, you can share your cluster’s Docker registry:
eval $(minikube docker-env). This way you won’t need to push your image to a remote shared registry.
By running the following command, you will instruct JKube to build a Docker image for your Maven project:
As I stated before, 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 image’s name. You can do so very easily using a Maven property:
1<properties> 2 <!-- ... --> 3 <jkube.generator.name>your-docker-hub-user/image-name:latest</jkube.generator.name> 4</properties>
You can now run the Maven goal to push your image:
JKube also provides a way to infer your project’s requirements and generate cluster configuration manifests (YAML files) for your application.
Again, if you are using one of the supported frameworks, all you’ll have to do is run:
Finally, you can deploy the generated configuration files to your cluster. Eclipse JKube internally uses 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.
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.
In case anything went wrong, or simply to delete your application from the cluster, you can run the following command:
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…
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.