Deploying Spring Boot Application on k8s

Converting Docker image into Pod and then Displaying Dashboard.

·

3 min read

Deploying Spring Boot Application on k8s

Photo by Jexo on Unsplash

introduction :

  • In this Blog, we are going to learn how to deploy the Java Spring boot application in K8s as a pod and finally display it as a Dashboard.

    Architecture :

  1. Launch an instance from an Amazon Linux 2 or Amazon Linux AMI with t2.medium

-> Go to AWS

How to create a free-tier Account

image

image

image

image

Note: t2.medium instance will incur some cost even if you have a free-tier account.

keypair will be your own. In my case, it's spring boot-demo

image

image

image

image

2. Connect to your instance.

3. Update the packages and package caches you have installed on your instance. $ yum update -y

4. Install the latest Docker Engine packages.

$ amazon-linux-extras install docker OR $ yum install docker -y

image

5. Start the Docker service. $ systemctl start docker $ systemctl enable docker

image

6. Install Conntrack and git: $ yum install conntrack -y $ yum install git -y

image

7. Install k8

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

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

image

8. Start Minikube $ /usr/local/bin/minikube start --force --driver=docker /usr/local/bin/minikube version

image

image

9. Install Kubectl

$ curl -LO "[dl.k8s.io/release/$(curl](https://dl.k8s.io.. -L -s https://dl.k8s.io/release/stable.txt)/bin/Linux/amd64/kubectl/bin/Linux/amd64/kubectl)" sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl /usr/local/bin/kubectl version

image

10. Clone the repo

$ cd /opt/

$ git clone https://github.com/DEVOPS-WITH-WEB-DEV/springboot- k8s.git

image

11. Make the DB UP

image

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

$ /usr/local/bin/kubectl exec -it mysql-f759455cd-2dh8m /bin/bash MySQL -u root -p give password as root

Enter the below command inside DB.

show databases;

image

image

12. Install Maven

$ yum install maven -y

image

Create the docker image

$ docker build -t charan63/spring-boot-crud-k8s:1.0

image

##13. docker login [ CREATE A DOCKER HUB ACCOUNT BEFORE ] Give docker hub username and password $ docker image push charan83/springboot-crud-k8s:1.0 .

image

image

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

/usr/local/bin/kubectl get svc

/usr/local/bin/minikube ip

image

14. PUT PORT FORWARD

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

[HOST PORT TO CONTAINER PORT]

kubectl port-forward --address 0.0.0.0 svc/{your service name} {external port to the Internet}:{your service port, the port your app is listening on in its container} for example, if my service is named store and is listening on 80 kubectl port-forward --address 0.0.0.0 svc/store 8888:80

image

15. JSON DATA TO BE HIT WITH POST

URL POST - http://:8080/orders

DATA TO SENT IN RAW TAB

{

"name": "chair",

"qty":3,

"price":39

}

image

16. FOR DASHBOARD:

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

image

IN OTHER TERMINAL

/usr/local/bin/minikube dashboard

Hit this URL in the browser

http://:8001/api/v1/namespaces/kubernetes- dashboard/services/http:kubernetes- dashboard:/proxy/#/pod?namespace=default

image

Thanks, Praveen Singampalli for the Live Demo on youtube

Did you find this article valuable?

Support CharanWrites by becoming a sponsor. Any amount is appreciated!