First make the jar file of our spring boot project by using below command
gradle build -X test
FROM openjdk:8
WORKDIR /app
ADD build/libs/ElectricityBillPaymentApp-0.0.1-SNAPSHOT.jar .
EXPOSE 8081
ENTRYPOINT ["java","-jar","ElectricityBillPaymentApp-0.0.1-SNAPSHOT.jar"]
version: '3.9'
services:
api:
build:
context: .
ports:
- "8080:8081"
depends_on:
db:
condition: service_healthy
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/postgres
- SPRING_DATASOURCE_USERNAME=pavan
- SPRING_DATASOURCE_PASSWORD=tiger
db:
image: postgres
volumes:
- db_data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=tiger
- POSTGRES_USER=pavan
healthcheck:
test: ["CMD-SHELL", "pg_isready -U pavan"]
interval: 10s
timeout: 5s
retries: 5
volumes:
db_data: {}
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo usermod -a -G docker ec2-user
sudo systemctl enable docker
sudo systemctl status docker
sudo yum install git
git clone url
In place of url mention your github Repository of Project
wget https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64
sudo chmod +x docker-compose-linux-x86_64
sudo mv docker-compose-linux-x86_64 docker-compose
sudo mv docker-compose /usr/local/bin/docker-compose
docker-compose up -d
Go to Ec2 Instance and copy the Ip address Also copy the port no from docker-compose file
Ip_Address:portno/swagger-ui.html
This Deployment is using Docker is Done. Now Lets see how to deploy the same project using Kubernates.
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo usermod -a -G docker ec2-user
sudo systemctl enable docker
sudo systemctl status docker
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo chmod +x kubectl
sudo mv kubectl /usr/bin/
sudo su -
kubectl
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
yum install conntrack -y
minikube start --vm-driver=none
sudo yum install git
git clone url
In place of url mention your github Repository of Project
kubectl apply -f file_name
In place of fine_name mention your deployment file names
Go to Ec2 Instance and copy the Ip address Also copy the port no of application on which it is running
You can get the port no by using below command
kubectl get all
To access the Api on browser
Ip_Address:portno/swagger-ui.html