You are on page 1of 5

Running Spring Boot Microservices on Kubernetes

Spring Boot is a Java-based open-source application that helps to create a


microservice. It is a lightweight framework that contains a complex infrastructure
that supports running business-ready applications very easily.

Spring Boot is good for Microservices because it helps to build production-ready


applications with different non-functional features.

If you want to Gain In-depth Knowledge on Spring Boot, please go through this
link Spring Boot Training

Kubernetes is an open-source platform that helps developers to deploy, manage


and scale applications automatically running in containers.

Spring Boot Kubernetes service discovery

Service Discovery is the process of finding how to connect service and its workflow.
To deploy and test the sample Microservices, here it is needed to create an
environment. We will understand the process step-wise but in a simple way.

#) First we need to install Minikube (Kubernetes). After installation, we can start


Minikube. Here are the steps. :-
$> minikube start

$> minikube config set vm-driver VirtualBox

$>kubectlconfig use-context minikube

#) After this, we need to check that kubectl is communicating with the cluster
correctly or not.
$> kubectl cluster-info

Here, the output will look like this:


To further diagnose cluster problems, use ‘kubectl cluster-info-dump’.

#) Later we can inspect the state of the cluster.


$> minikube dashboard

The above command will open the site in a default browser.

Now, we can see that the cluster is started running and it is ready to deploy. Here
we will create a Demo application named “Hello World”, which consists of Spring
Boot services called “backend and frontend”.

Deployment of Backend application with simple commands


Here we will check the deployment of the demo application in different steps.

Deployment creation:-

⮚ Here we use kubectl, to pass the required commands.


$> kubectl run demo-backend --image=demo-backend: latest \

--port=8080 --image-pull-policy Never


Here we can see that we have created a demo-backend deployment. The
“port=8080” specifies that deployment opens the port 8080. The image-pull-policy-
never flag says that Minikube doesn’t pull the image from the register.

Deployment Verification:-

● Here we can check whether the deployment is successful.


$>kubectl get deployments

● The result of the above deployment will be like this. :-


NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
Demo-backend 1 1 1 1 20s

To check the application logs, we need the respective POD id.


$>kubectl get pods
$>kubectl logs <pod id>

Creating a deployment service

Hereunder, we can see that “-type=NodePort” specifies that the service is available
from the outside cluster.

$> kubectl expose deployment demo-backend --type=NodePort

Now we will check whether the service created successfully With Spring Boot
Course
$> kubectl get service

The result can be seen here;


NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

demo-backend NodePort 10.106.11.133 <none> 8080:30117/TCP 11m

Thus, the above command shows that we have a service “demo-backend”,


type=NodePort, that is available on the cluster-IP “10.106.11.133”.

Calling back service


Here we will call back the service the first time.
$> minikube service demo-backend

The above command will start the default browser.

Cleaning the service and its deployment

Here we can remove the service and deployment of backend demo.


$>kubectl delete service demo-backend
$>kubectl delete deployment demo-backend

Deployment of front-end application with simple commands


The front-end deployment is somehow similar to the backend one. Here we will
check by using specific commands on Spring Boot Online Course

Creating Deployment
$>kubectl create -f frontend-deployment.yaml

Verifying the deployment


$>kubectl get deployments
$>kubectl get services

Calling back the endpoint


$> minikube service demo-frontend

Clearing services and deployment

In the end, we can remove all the services and their deployment.
$>kubectl delete service demo-frontend
$>kubectl delete deployment demo-frontend
$>kubectl delete service demo-backend
$>kubectl delete deployment demo-backend

Kubernetes Microservices example


Here we will try to understand the example that uses Kubernetes in the Docker
environment. Kubernetes supports load-balancing and service discovery.

This demo system in the Docker container creates a complete microservice. This
service is applied in Java by using spring and spring clouds.

It uses three different kinds of microservices.

1) Order 2) Customer and 3) Catalog

Apache HTTP load balancer

Apache HTTP is used to provide the demo on the web page. It also forwards
requests of HTTP to the microservices. Here Apache HTTP is configured as a reverse
proxy and Kubernetes handles the load-balancing.

Results of the code

⮚ Microservices-Kubernetes-demo-order takes care of order processing.


⮚ Microservices-Kubernetes-demo-customer deals with customers.
⮚ Microservices-Kubernetes-demo-catalog deals with items.

Other microservices use built-in DNS in Kubernetes.

Thus, the above article gives an overview of running spring boot-microservices on


Kubernetes. It gives an idea about the process of microservices. Here we have
discussed some examples of the demo application that shows how the
microservices are deployed using various commands. One can gain knowledge
about spring boot and Kubernetes by using different online platforms at their ease.
Enroll live free demo on Spring Boot Online Training

You might also like