DEV Community

Vishal Bharti
Vishal Bharti

Posted on

Deploy Spring Boot Application on K8S using Minikube and Docker Desktop.

GitHub Linkk8s-vishal-bharti-demo

Prerequisites: Docker Desktop Installed, Minikube Installed

For Windows: use Git Bash command line.

  • Step-1: Start Minikube
minikube start
Enter fullscreen mode Exit fullscreen mode

It will start the single node cluster for kubernetes. For 1st time it will take upto 5 minutes or more depending upon your sytem configuration and network speed.

  • Step-2: Set Docker as Minikube Environment.
eval $(minikube -p minikube docker-env)
Enter fullscreen mode Exit fullscreen mode

Only for Windows: This will configure your docker in minikube environment till your git bash command line is active. When you close or open new window of git bash you need to use this command in every terminal.

  • Step-3: Build Jar file of spring boot application.

Open the Git Hub project in Intellij or some Ide and build the jar file.

If you use Intellij then you can build this from Maven on side and navigate to product and then Lifecycle and then Install.

Maven->k8s-vishal-bharti-demo->Lifecycle->install

*Jar file name should k8s-vishal-bharti-demo.jar .

After this step for command to run you need to be in root directory of your project or in root directory of given application.

  • Step-4: Build Docker Image.
docker build -t k8s-vishal-bharti-demo:1.0 -f devops/docker/Dockerfile .
Enter fullscreen mode Exit fullscreen mode

This command will build the docker image of spring-boot application.

  • Step-5: Creating Deployment on K8s.

We need to create deployment file which is already present in repo. This file will create number of pods as configured in deployment.yaml file as replicas. In this I created 3replica set.

kubectl apply -f devops/kube/deployment.yaml
Enter fullscreen mode Exit fullscreen mode

This will create 3 pods on the k8s cluster. We can check with command:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Now After this application will run in k8s cluster with 3 pods but for accessing those we need single IP and Port. So for that we will deploy service as type: LoadBalancer which will balance the load to these three pods.

  • Step-6: Creating Service on K8s.

We need to create Service file which is already present in repo. This file will create service to access application.

kubectl apply -f devops/kube/service.yaml
Enter fullscreen mode Exit fullscreen mode

We can check service with command:

kubectl get svc
Enter fullscreen mode Exit fullscreen mode

This will show our service as service name k8s-vishal-bharti-demo-svc.

**

  • Step-7: Tunnelling Minikube Service.

Now After this to access our service from localhost we need to tunnel minikube Ip to localhost.

minikube tunnel
Enter fullscreen mode Exit fullscreen mode

Congrats We successfully Deployed our application in K8s.

We can access application now from localhost:9000 as configured in service.yaml .
Thanks For Check in My Blog on Medium.
Contact me on my mail vishalbharti0000@gmail.com and Linkedin for any queries.
Linkedin Profile: https://www.linkedin.com/in/vishalbharti0000/

Top comments (1)

Collapse
 
ajeetraina profile image
Ajeet Singh Raina

Why not use Kubernetes that comes with Docker Desktop? You don't need to install Minikube.