-- RDS database (Mariadb)
--EKS cluster
--EC2 instance
step 1 Database setup --Clone the repository
git clone (repostories's url) git clone https://github.com/Rohit-1920/EasyCRUD-Updated.git-- Enter in database using
mysql -h (RDS endpoint) -u admin -penter the root password
create new database and user
CREATE DATABASE student_db;
GRANT ALL PRIVILEGES ON springbackend.* TO 'username'@'localhost' IDENTIFIED BY 'your_password';replace the username and your_password which you have created
use that created database
use student_db;creat table
CREATE TABLE `students` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`course` varchar(255) DEFAULT NULL,
`student_class` varchar(255) DEFAULT NULL,
`percentage` double DEFAULT NULL,
`branch` varchar(255) DEFAULT NULL,
`mobile_number` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;exitcd EasyCRUD-Updated/backendcp src/main/resources/application.properties .create dockerfile for backend
nano dockerfileDockerfile data
FROM maven:3.8.3-openjdk-17
COPY . /opt
WORKDIR /opt
RUN rm -rf src/main/resources/application.properties
RUN cp -rf application.properties src/main/resources
RUN mvn clean package
WORKDIR /opt/target
EXPOSE 8080
CMD ["java" , "-jar" , "student-registration-backend-0.0.1-SNAPSHOT.jar"]build backend image
docker build . -t backend:v1--check the created image
docker imageslogin to dockerhub using
docker login -u usernametag image
docker tag oldname (username)/newnamePush the image to the dockerhub using
docker push (username)/newnameNow create Pod file for backend
nano pod.yamlPod file data
apiVersion: v1
kind: Pod
metadata:
name: backend
labels:
app: backend
spec:
containers:
- name: backend
image: kartikborude/backend:latest
ports:
- containerPort: 80Create the service file for backend
nano svc.yamlData for svc
apiVersion: v1
kind: Service
metadata:
name: backend-svc
spec:
type: LoadBalancer
selector:
app: backend
ports:
- port: 8080
targetPort: 8080kubectl apply -f pod.yaml
kubectl apply -f svc.yamlAfter that
kubectl get svccopy the generated DNS of backend and paste it in the .env file of frontend
cd ../frontendEdit .env file
nano .envinstead of ip address paste the copied dns from backend
VITE_API_URL=http://___:8080/api
VITE_API_URL=http://ab0a4bbf1276142afbabac8db6418234-2033286948.ap-southeast-2.elb.amazonaws.com:8080/api
create dockerfile for frontend
nano dockerfiledata for dockerfile
FROM maven:3.8.3-openjdk-17
COPY . /opt
WORKDIR /opt
RUN rm -rf src/main/resources/application.properties
RUN cp -rf application.properties src/main/resources
RUN mvn clean package
WORKDIR /opt/target
EXPOSE 8080
CMD ["java" , "-jar" , "student-registration-backend-0.0.1-SNAPSHOT.jar"]build the image using
docker build . -t frontend:v1tag image
docker tag oldname (username)/newnamePush the image to the dockerhub using
docker push (username)/newnameCreate the Deployment file for frontend
nano deploy.yamldata for deploy file
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
labels:
app: frontend
spec:
replicas: 3
selector:
matchLabels:
app: frontend
template:
metadata:
name: frontend
labels:
app: frontend
spec:
containers:
- name: frontend
image: kartikborude/frontend:latest
ports:
- containerPort: 80Create service ffile for frontend
nano svc.yamldata for service file for frontend
apiVersion: v1
kind: Service
metadata:
name: frontend-svc
spec:
type: LoadBalancer
selector:
app: frontend
ports:
- port: 80
targetPort: 80Run both file using
kubectl apply -f deploy.yaml
kubectl apply -f svc.yaml The created DNS of frontend we have run on google or any browser
DNS will be visible using
kubectl get svc