Skip to content

Latest commit

 

History

History

Deploying-Spring-Boot-K8S

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Deploying Spring Boot application on Kubernetes

In this article we are deploying Spring Boot application on K8S

Step-by-Step Implementation:-

Step 1 — Create an t2.medium Instance

Step 2 — Install the following command in instance

sudo su
yum update -y
yum install docker -y
systemctl enable docker
systemctl start docker
systemctl status docker
docker — version

Step 3 — Install Conntrack

conntrack :- In Kubernetes, “conntrack” refers to the Connection Tracking system used for network traffic management within the cluster. Conntrack is a kernel feature that keeps track of network connections and their states. It allows the kernel to maintain information about network connections, such as source IP addresses, destination IP addresses, ports, and connection states (established, closed, etc.)

yum install conntrack -y

Step 4 — Install and run minikube in vm

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube

/usr/local/bin/minikube start --force --driver=docker

After that we can check the minikube version ,

/usr/local/bin/minikube version

Step 5 — Install kubectl command , given permission to kubectl and check version of it.

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

/usr/local/bin/kubectl version

Step 6 — Install git and clone the repository as ,

yum install git -y
cd /opt
git clone https://github.com/SushantOps/SpringBootOnK8S_PS.git

Step 7 — Now we will start setting up Database

To create the persistent database and other services.

/usr/local/bin/kubectl get pods

/usr/local/bin/kubectl create -f db-deployment.yaml

kubectl get pods

check database and it’s content so go inside the container as , ( password is root ) so we can see the db create from the container .

/usr/local/bin/kubectl exec -it <POD_NAME>/bin/bash

mysql -u root -p

After that exit from the shell also container.

Install maven now and check version.

yum install maven -y
mvn -v

Step 8 — Create an image from Dockerfile as ,

docker build -t <dockerhub_name>/<image_name> .

docker build -t sushantkapare1717/springboot-crud-k8s:1.0 .

#check the docker images 
docker images

Now push that image to dockerhub so first you have to login to dockerhub and then push that image to docker hub

docker login

docker push sushantkapare1717/springboot-crud-k8s

Step 9 — now create app-deployment.yml file and check pods and check service

/usr/local/bin/kubectl apply -f app-deployment.yaml

/usr/local/bin/kubectl get pods

/usr/local/bin/kubectl get svc

now check minikube ip as,

/usr/local/bin/minikube ip

PORT-FORWARDING

Port forwarding is a networking technique used to redirect network traffic from one port on a host to another port on a different host or the same host. In the context of Kubernetes, port forwarding allows you to access services running inside a Kubernetes cluster from your local machine or another remote host.

/usr/local/bin/kubectl port-forward --address 0.0.0.0 svc/springboot-crud-svc 8080:8080 &

Step 10 — go to POSTMAN and check the methods you get replay

Now go to the database in the server and check the entries done by you in the SQL database.

/usr/local/bin/kubectl exec -it <mysql_pod_name>/bin/bash

step 11 — Now we will open the Dashboard of K8S. Inside EC2 our minikube is running so we are setting a proxy for all the local address.The proxy server is started on port 8001.

/usr/local/bin/kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'

Now open another terminal and run below command.

/usr/local/bin/minikube dashboard

http:https://127.0.0.1:34927/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
change the IP address to your IP address and port mention as 8001

e.g http:https://54.190.118.228:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

So you can access the k8s resources on dashboard as ,

If you like this article, please share with others. ❤️