Deploy Java app on Kubernetes with JKube
Build and Deploy java applications on Kubernetes without any hassle
Welcome everyone. Today we will deploy a java spring-boot web app on the Kubernetes cluster using the Eclipse JKube maven plugin.
Now you're thinking what is Eclipse JKube?
Eclipse JKube is a maven plugin to build container images and deploy Java applications on the Kubernetes/Openshift cluster without writing any Kubernetes manifests file. It automatically detects the framework used in the application and generates cluster configuration files and deploys them on Kubernetes/Openshift cluster. Not only this it supports various configurations to know more about it please visit https://www.eclipse.org/jkube/
Requirements
Jdk 17+
Docker
Kubernetes cluster
That's all you need.
Clone the repository https://github.com/anurag-rajawat/spring-boot-hello-world.git and change the directory to spring-boot-hello-world
Start your cluster and expose your docker-daemon to build docker images directly inside the minikube cluster.
$ minikube start
$ eval $(minikube -p minikube docker-env)
Package the application
$ ./mvnw clean package
Our application is successfully packaged.
Now comes the interesting part which is deploying the app on the cluster. So let's deploy
$ ./mvnw k8s:build k8s:resource k8s:apply
By default, JKube will generate resource descriptors for Kubernetes deployment. In our case not only deployment but NodePort
service resource descriptors will be generated as well because I explicitly told JKube to generate NodePort
service by configuring service type, otherwise we've to manually expose our deployment or do port-forwarding to access our application.
As we can see the build is successful. So, let's check the application deployment, pod, and service status, and then we see what are these goals.
Voilà our application is successfully running 🥳
Now, let's discuss what are those goals:
k8s: build
: This goal is responsible for creating the Docker images containing the actual application. These then can be deployed later on Kubernetes or OpenShift cluster.k8s:resource
: This goal generates the Kubernetes resource descriptors which are packaged within the maven artifacts and can be deployed to the Kubernetes or Openshift cluster.k8s:apply
: This goal applies the resource descriptors generated previously to a connected Kubernetes or Openshift cluster.
If you're curious you can check the resource descriptors in the target/classes/META-INF/jkube
directory
So far so good, let's access the application
$ minikube service spring-boot-hello-world --url
Invoke the service URL in your favorite browser and you can see like 👇
/
endpoint
<url>/greeting?name=User
endpoint
As we can see our application is working properly.
We deployed our app using JKube on Kubernetes without any hassle. If we try to deploy it without JKube then we have to write a Dockerfile, build the image, and then resource descriptors which are quite complex.
JKube made our life so much easier and enhances our productivity by helping us to focus only on building our application rest will be handled by JKube.
JKube also offers Kubernetes Remote Development feature which is very interesting. You can check more about it at JKube Remote Development. If you want more information about JKube please click here.
I hope you find this useful. Thank you so much for taking your valuable time to read.