Deploy any Spring Boot application into Kubernetes using Eclipse JKube

Rohan Kumar
4 min readJul 25, 2020

--

Note: This blog is a part of blog Series: Deploying Java applications onto Kubernetes using Eclipse JKube

Today in this blog, I would be talking about a project called Eclipse JKube and how it helps in deploying java applications onto Kubernetes without any problems.

We would be deploying one of the Spring Boot Quick starts onto Kubernetes using the tool. But first we need to make sure our Kubernetes Cluster is running. I am using minikube so I started it using this command:

minikube start

Once, minikube is running. We need build docker image in minikube. If you were using some other Kubernetes Cluster, you would need to build and push to some docker registry. You need to expose minikube VM’s internal docker daemon to your terminal session using the following command:

# To point your shell to minikube's docker-daemon, run:
# eval $(minikube -p minikube docker-env)

Now we’re all set with respect to deploying our Spring Boot application onto Kubernetes. We would be using one of the famous quickstarts: Spring Petclinic

We’ll clone the project first:

git clone https://github.com/spring-projects/spring-petclinic.git

We’ll compile project afterwards:

mvn clean install

Now we are all set to deploying this application onto Kubernetes. We’ll be deploying this using Eclipse JKube so we will issue Eclipse JKube’s Kubernetes Maven Plugin goals to achieve this:

mvn org.eclipse.jkube:kubernetes-maven-plugin:build \
org.eclipse.jkube:kubernetes-maven-plugin:resource \
org.eclipse.jkube:kubernetes-maven-plugin:apply

You can see your application getting deployed like the screenshot below:

Eclipse JKube deploying application in Kubernetes

Okay, so you can see that k8s:build goal created a docker image and k8s:resource and k8s:apply goal created and applied Kubernetes manifests for you onto Kubernetes Cluster. You would be able to see your application running:

~/work/repos/spring-petclinic : $ docker images | grep petclinic
samples/spring-petclinic latest 2f3bf8cb72e6 About a minute ago 493MB
~/work/repos/spring-petclinic : $ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-5bf87f5f59-8762t 1/1 Running 1 18h
spring-petclinic-dfd4ccd98-dv2f7 1/1 Running 0 2m
~/work/repos/spring-petclinic : $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d17h
spring-petclinic ClusterIP 10.111.197.212 <none> 8080/TCP 3m12s

But the service created is of type ClusterIP(that’s the default Service created by Eclipse JKube), you won’t be able to access it from outside the cluster. We need to provide an additional property as parameter to Eclipse JKube. So I would add this additional property in my previous JKube command:

~/work/repos/spring-petclinic : $ mvn \
org.eclipse.jkube:kubernetes-maven-plugin:build \ # Build org.eclipse.jkube:kubernetes-maven-plugin:resource \ # K8s Yamls org.eclipse.jkube:kubernetes-maven-plugin:apply \ # Apply K8s Yaml -Djkube.enricher.jkube-service.type=NodePort # SVC-Type = NodePort

Once, you run this command you would see that plugin has updated Deployment and Service :

Updating Service to type NodePort

Now we should be able to access our application from outside minikube. To do this, we need to run this command:

~/work/repos/spring-petclinic : $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d17h
spring-petclinic NodePort 10.111.197.212 <none> 8080:32567/TCP 11m
~/work/repos/spring-petclinic : $ minikube service spring-petclinic
|-----------|------------------|-------------|-----------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------------|-------------|-----------------------------|
| default | spring-petclinic | http/8080 | http://192.168.39.145:32567 |
|-----------|------------------|-------------|-----------------------------|
🎉 Opening service default/spring-petclinic in default browser...
~/work/repos/spring-petclinic : $

This would open up your application in your default browser, You can now test it and see if everything is working.

Spring Boot Petclinic Deployed into Kubernetes using Eclipse JKube

Once everything is done, you can simply undeploy your application from Kubernetes using k8s:undeploy goal:

mvn org.eclipse.jkube:kubernetes-maven-plugin:undeploy

And that’s it for today, you can find more about the project by visiting project website:

This blog post is also published on Wordpress

--

--

No responses yet