This repository contains a sample application that has multiple microservices where i've deployed microservices on Docker, Kubernetes
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://100.25.193.105:1001/api/v1
shoe:
path: /shoe/**
url: http://100.25.193.105:1002/api/v1
wishlist:
path: /wishlist/**
url: http://100.25.193.105:1003
cart:
path: /cart/**
url: http://100.25.193.105: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 Docker-Server and login to the Docker-Server. Install Git & Docker.
- Step 2 - Update your Docker-Server public ip in ui-web-app-reactjs, zuul-api-gateway in GitHub
- Step 3 - Clone the Microservices-Deployment repository.
- Step 4 - Create a Dockerfile for each microservice, build the Dockerfile, and run it as a container.
- Step 5 - Access the application
Step 1 - Create an instance named Docker-Server and login to the Build-Server. Install Git & Docker.
- 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 Docker-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 Docker-Server: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 Docker-Serverip:1001/api/v1
shoe:
path: /shoe/**
url: http://100.25.193.105:1002/api/v1 # http://your Docker-Serverip:1001/ap2/v1
wishlist:
path: /wishlist/**
url: http://100.25.193.105:1003 # http://your Docker-Serverip:1003
cart:
path: /cart/**
url: http://100.25.193.105:1004/api/v1 # http://your Docker-Serverip: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
Step 4.1 - Create a Dockerfile for ui-web-app-reactjs, build the Dockerfile, and run it as a container
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"]
git status
git add Dockerfile
git commit -m "created Dockerfile for ui microservice"
git push origin main
- Give Github Credentials & Check in Github can able to see Dockerfile
- 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.
Whenever you click on shoes, offers, cart, or wishlist, you are not able to access the particular microservices.
Step 4.2 - Create a Dockerfile for zuul-api-gateway, build the Dockerfile, and run it as a container
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.
git status
git add Dockerfile
git commit -m "created Dockerfile for zuul microservice"
git push origin main
- Give Github Credentials & Check in Github can able to see Dockerfile
- 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.
Step 4.3 - Create a Dockerfile for shoes-microservice-spring-boot, build the Dockerfile, and run it as a container
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"]
git status
git add Dockerfile
git commit -m "created Dockerfile for shoes microservice"
git push origin main
-
Give Github Credentials & Check in Github can able to see Dockerfile
-
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.
Step 4.4 - Create a Dockerfile for offers-microservice-spring-boot, build the Dockerfile, and run it as a container
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"]
git status
git add Dockerfile
git commit -m "created Dockerfile for offers microservice"
git push origin main
- Give Github Credentials & Check in Github can able to see Dockerfile
- 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.
Step 4.5 - Create a Dockerfile for cart-microservice-nodejs, build the Dockerfile, and run it as a container
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"]
git status
git add Dockerfile
git commit -m "created Dockerfile for cart microservice"
git push origin main
- Give Github Credentials & Check in Github can able to see Dockerfile
- 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 1004:1004 cart
- Note - Open port 1004 in the Security Group inbound rules.
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"]
git status
git add Dockerfile
git commit -m "created Dockerfile for wishlist microservice"
git push origin main
-
Give Github Credentials & Check in Github can able to see Dockerfile
-
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.
Step 5 - Access the application - Whenever you click on a particular service, you will get a response.
- Browse - http://100.25.193.105:8080/
- Click (Shoes) - Will get a response like this {"tommy":"Tommy Hilfiger Shoe","adidas":"Adidas Running Shoe","nikeshoe":"Nike Sports Shoe"}
-
Click (Offers) - will get a response like this {"samsung":"Samsung 10% Discount","adidas":"Adidas Shoe 70% Off","nikeshoe":"Nike Sports Shoe 50% off"}
-
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"}]}
- Click (Wishlist) - Will get a response like this {"1": "Apple Iphone", "2": "MacBook", "3": "Your Fav Something else"}