This repository contains a sample application that has multiple microservices that I've Dockerized and deployed on a Kubernetes cluster.
Special thanks to Deekshith for contributing to this project. Deekshith wrote the Code for the microservices and creating Application Architecture Design. Thank you for your hard work and dedication to this project.
In the UI, as the user clicks on a specific button, specific data is sent to API-Gateway, and depending on that, it will validate the request and redirect to a specific microservice (respective API).
The application consists of 6 different Microservices. Architecture of sample multiple microservices developed in different technologies - Spring Boot, Node.js, Python, React.js in a project. Microservices connected by an API Gateway using Netflix Zuul.
- ui-web-app-reactjs - Single Page Application that provides the UI
- Click (ui-web-app-reactjs)
- Click (src)
- Click (Components)
- Click (App.jsx)
<button name="shoe/shoes" onClick={handleApiCall} style={{margin:'0px 10px'}}>Shoes</button>
<button name="offer/offers" onClick={handleApiCall} style={{margin:'0px 10px'}}>Offers</button>
<button name="cart" onClick={handleApiCall} style={{margin:'0px 10px'}}>Cart</button>
<button name="wishlist" onClick={handleApiCall} style={{margin:'0px 10px'}}>Wishlist</button>
-
zuul-api-gateway - API gateway that proxies all the micro-services
-
Click (Zuul-api-gateway)
-
Click (src)
-
Click (main)
-
Click (resources)
-
Click (application.yml)
This is where you need to configure if my suffix is offer, shoe, wishlist, or cart to go to this particular api. Depending on whatever the URL that i recieve it from UI defining what is the destination to reach.
offer:
path: /offer/**
url: http://44.199.250.205:1001/api/v1
shoe:
path: /shoe/**
url: http://44.199.250.205:1002/api/v1
wishlist:
path: /wishlist/**
url: http://44.199.250.205:1003
cart:
path: /cart/**
url: http://44.199.250.205:1004/api/v1
- cart-microservice-nodejs - Node.js App with Cart data
- offers-microservice-spring-boot - Spring Boot App with Offers data
- shoes-microservice-spring-boot - Spring Boot App with Shoe data
- wishlist-microservice-python - Python App with Wishlist data
- Docker
- Kubernetes
- Step 1 - Create an instance named Build-Server and login to the Build-Server. Install Git & Docker.
- Step 2 - Update your Build-Server public ip in ui-web-app-reactjs, zuul-api-gateway in GitHub
- Step 3 - Clone the Microservices-Deployment repository.
- Become root user
sudo su -
yum install git -y
yum install docker -y
service docker start
service docker status
- To confirm weather docker service is running or not
docker info
Step 2 - Fork the repository. Update your Build-Server public ip in ui-web-app-reactjs, zuul-api-gateway in your GitHub.
- Click (ui-web-app-reactjs)
- Click (src)
- Click (Components)
- Click (App.jsx)
const url = 'http://100.25.193.105:9999/'+e.target.name; # http://give your Build-Serverip:9999/
- Click (Zuul-api-gateway)
- Click (src)
- Click (main)
- Click (resources)
- Click (application.yml)
server:
port : 9999
zuul:
routes:
offer:
path: /offer/**
url: http://100.25.193.105:1001/api/v1 # http://your Build-Serverip:1001/api/v1
shoe:
path: /shoe/**
url: http://100.25.193.105:1002/api/v1 # http://your Build-Serverip:1001/ap2/v1
wishlist:
path: /wishlist/**
url: http://100.25.193.105:1003 # http://your Build-Server ip:1003
cart:
path: /cart/**
url: http://100.25.193.105:1004/api/v1 # http://your Build-Server ip:1004/api/v1
- In UI, we need to give the information about the API server.
- In an API server, we need to give information about API services.
git clone https://github.com/Bathalapalli-SaiRangaPavan/Microservices-Deployment.git # https://github.com/<giveyourrepositoryname>/Microservices-Deployment.git
- Go inside the cloned repository
cd Microservices-Deployment
- List the Files and Directories inside the repository
ls
cd ui-web-app-reactjs
- Create a Dockerfile based on the instructions. ui-web-app-reactjs
FROM node:8
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 8080
CMD ["npm","start"]
- Build to create an image
docker build -t ui .
- Check the Images
docker images
- Create a container from the image.
docker run -d --name ui-container -p 8080:8080 ui
- Check the process status
docker ps
-
Note - Open port 8080 in the Security Group inbound rules.
-
Browse - http://yourdockerip:8080/
Whenever you click on shoes, offers, cart, or wishlist, you are not able to access the particular microservices.
cd zuul-api-gateway
- Create a Dockerfile based on the instructions. zuul-api-gateway
# multi stage build
FROM maven as build
WORKDIR /app
COPY . .
RUN mvn clean install
FROM openjdk:11.0.10-jre
WORKDIR /app
COPY --from=build /app/target/zuul-0.0.1-SNAPSHOT.jar .
EXPOSE 9999
CMD ["java","-jar","zuul-0.0.1-SNAPSHOT.jar"]
-
Note - If you go for multistage, you can reduce the image size.
-
Build to create an image
docker build -t zuul .
- Check the Images
docker images
- Create a container from the image
docker run -d --name zuul-container -p 9999:9999 zuul
docker logs zuul-container
-
It Started in 8.83 seconds
-
Note - Open port 9999 in the Security Group inbound rules.
cd ..
cd shoes-microservice-spring-boot
- Create a Dockerfile based on the instructions. shoes-microservice-spring-boot
FROM maven as build
WORKDIR /app
COPY . .
RUN mvn install
FROM openjdk:11.0.10-jre
WORKDIR /app
COPY --from=build /app/target/shoes-0.0.1-SNAPSHOT.jar /app
EXPOSE 1002
CMD ["java","-jar","shoes-0.0.1-SNAPSHOT.jar"]
- Build to create an image
docker build -t shoes .
- Check the Images
docker images
- Create a container from the image
docker run -d --name shoes-container -p 1002:1002 shoes
- Note - Open port 1002 in the Security Group inbound rules.
- Click (Shoes) - Will get a response like this {"tommy":"Tommy Hilfiger Shoe","adidas":"Adidas Running Shoe","nikeshoe":"Nike Sports Shoe"}
cd ..
cd offers-microservice-spring-boot
- Create a Dockerfile based on the instructions. offers-microservice-spring-boot
FROM maven as build
WORKDIR /app
COPY . .
RUN mvn install
FROM openjdk:11.0.10-jre
WORKDIR /app
COPY --from=build /app/target/offers-0.0.1-SNAPSHOT.jar /app
EXPOSE 1001
CMD ["java","-jar","offers-0.0.1-SNAPSHOT.jar"]
- Build to create an image
docker build -t offers .
- Check the Images
docker images
- Create a container from the image
docker run -d --name offers-container -p 1001:1001 offers
- Note - Open port 1001 in the Security Group inbound rules.
- Click (Offers) - will get a response like this {"samsung":"Samsung 10% Discount","adidas":"Adidas Shoe 70% Off","nikeshoe":"Nike Sports Shoe 50% off"}
cd ..
cd cart-microservice-nodejs
-
Create a Dockerfile based on the instructions. cart-microservice-nodejs
-
Note - It depends on the version if u go with latest version it might not work as expected
FROM node:14
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 1004
CMD ["node","index.js"]
- Build to create an image
docker build -t cart .
- Check the Images
docker images
- Create a container from the image
docker run -d --name cart-container -p 1001:1001 cart
-
Note - Open port 1004 in the Security Group inbound rules.
-
Click (Cart) - will get a response like this {"data":[{"itemNo":1,"item":"Nike Shoe"},{"itemNo":2,"item":"Tommy Hilfiger Shirt"},{"itemNo":3,"item":"Calvin Klien Trousers"}]}
cd ..
cd wishlist-microservice-python
- Create a Dockerfile based on the instructions - wishlist-microservice-python
FROM python:3
COPY . .
RUN pip install flask flask_cors
EXPOSE 1003
CMD ["python","index.py"]
- Build to create an image
docker build -t wishlist .
- Check the Images
docker images
- Create a container from the image
docker run -d --name wish-container -p 1003:5000 wishlist
- Note - Open port 1003 in the Security Group inbound rules.
- Click (Wishlist) - Will get a response like this {"1": "Apple Iphone", "2": "MacBook", "3": "Your Fav Something else"}
git status
git add .
git commit -m "created Dockerfile for microservices"
git push origin main
- Give Github Credentials
- Check in Github can able to see Dockerfile