MICROSERVICES ARCHITECTURE
MICROSERVICES ARCHITECTURE
MICROSERVICES ARCHITECTURE
MICROSERVICES ARCHITECTURE
SUBMITTED BY
KHAN UNNIZA FAKRUL HUSSAIN
APPLICATION ID: 36923
SEAT NO: 4500165
ACADEMIC YEAR
2023-2024
CONDUCTED AT
RIZVI COLLEGE OF ARTS, SCIENCE AND COMMERCE
BANDRA (W), MUMBAI 400050
University of Mumbai
Institute of Distance & Open Learning
Certificate
This is to certify that
Ms. UNNIZA KHAN Application ID: 36923, Seat No: 4500165 from Rizvi College of Arts,
Science and Commerce Bandra(W), Mumbai 400 050 has successfully completed all the
practical of Paper I titled MICROSERVICES ARCHITECTURE for M.sc (IT) Part I in the
academic year 2023-2024.
Section I
Section II _
Practical No Details
1 Implement Decision tree classification techniques
Description:
1)Install .Net Core Sdk (Link: https://dotnet.microsoft.com/learn/dotnet/hello-worldtutorial/install)
2)create folder MyMVC folder in D: drive or any other drive
Output:
− Go to controllers folder and modify HomeController.cs file
to match following: using System;
using System.Collections.Generic;
using System.Diagnostics; using
System.Linq;
using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using
Microsoft.Extensions.Logging; using MyMVC.Models; namespace
MyMVC.Controllers
{
4
}
Run the project Now open browser and and type URL: localhost:5000
Now go back to command prompt and stop running project using CTRL+C
5
− Now Add View to folder then home folder in it and modify
index.cshtml file to match following
@{
<div>
</div>
6
dotnet run
Practical No: 02
7
Aim: Building ASP.NET Core REST API.
Description:
Software requirement:
https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install
Check everything installed correctly
Once you've installed, open a new command prompt and run the
following command: Command prompt
> dotnet
output:
Command:
8
Output
:
Output:
Now Change the content:
To get started, remove the WeatherForecast.cs
file from the root of the project and the
WeatherForecastController.cs file from the
Controllers folder.
Add Following two files
9
public class GlossaryItem
[ApiController] [Route("api/[controller]")]
Term= "HTML",
},
new GlossaryItem
Term= "MVC",
},
10
new GlossaryItem
Term= "OpenID",
}
;
[HttpGet] public ActionResult<List<GlossaryItem>>
Get()
{ return Ok(Glossary);
if (glossaryItem == null)
{ return NotFound();
} else
return Ok(glossaryItem);
11
if (existingGlossaryItem != null)
else
Glossary.Add(glossaryItem);
if (existingGlossaryItem == null)
} else
existingGlossaryItem.Definition =
glossaryItem.Definition; return Ok();
}}
12
var glossaryItem = Glossary.Find(item => item.Term.Equals(term,
StringComparison.InvariantCultureIgnoreCase));
if (glossaryItem == null)
{ return NotFound();
else
{
Glossary.Re
move(glossaryIte m);
return NoContent();
13
Output:
14
output:
On Command prompt2:
1) Getting a list of items:
Command:
Output:
15
curl --insecure -X POST -d "{\"term\": \"MFA\", \"definition\":\"An
authentication process.\"}" -H "Content- Type:application/json" https://localhost:5001/api/glossary
Output:
Update Item
Command:
curl --insecure -X PUT -d "{\"term\": \"MVC\",
\"definition\":\"Modified record of Model View Controller.\"}" -H
"Content-Type:application/json" https://localhost:5001/api/glossary
Output:
Delete Item
Command:
curl --insecure --request DELETE --url https://localhost:5001/api/glossary/openid Output:
16
17
Practical No: 03
Aim: Working with Docker, Docker Commands, Docker Images and
Containers Description:
Step 1: create Docker Hub account (sign up)
Step 2 : login to https://labs.play-with-docker.com/
Click on start
18
Command: to check docker
version
docker –version
Output:
4) perform following:
Method1:
19
To pull and push images using docker
output:
4) perform following:
Method1:
20
Command: to check docker
version docker –version
output:
Output
21
Check it in docker hub now
Method 2:
22
Build an image then push it to docker and run it
Output :
output:
23
Command: to push image to docker hub
docker push kbdocker11/repo2 .
Output:
24
Practical No: 04
Description:
If you’ve already run the command to get started with the tutorial, congratulations!
If not, open a command prompt or bash window, and run the command:
You’ll notice a few flags being used. Here’s some more info on them:
What is a container?
25
Now that you’ve run a container, what is a container? Simply put, a container is simply
another process on your machine that has been isolated from all other processes on the host
machine. That isolation leverages kernel namespaces and cgroups, features that have been in Linux
for a long time. Docker has worked to make these capabilities approachable and easy to use.
Step 3: $ docker ps
26
Step 4: curl http://localhost:8080/will/it/blend?
27
Practical No: 05
Aim: Working with Docker Swarm.
Description:
What is Docker Swarm?
Docker Swarm is an orchestration management tool that runs on Docker applications. It helps end-
users in creating and deploying a cluster of Docker nodes.
28
To check the installed Docker version, enter the following command:
p0.0.0.0:80:80 mysql:latest
Now, Docker pulls the latest MySQL image from the hub. List down all the available Docker images on
your machine by using the following command:
sudo docker ps -a
Manager Node
This means that the manager node is successfully configured. Now, add worker node by copying
the command of the “swarm init” and paste the output onto the worker node:
Your worker node is also created if you see the following output:
Worker Node
Now, go back to the manager node and execute the following command to list the worker node: sudo
docker node ls
Here, you must see the worker node in the following output:
The above image shows you have created the Swarm Cluster successfully. Now, launch the service in
Swarm Mode. Go to your the manager node and execute the command below to deploy a service:
29
By executing the above command, you can access the HelloWorld file from the remote system. To see
the output, you can check the services with the following command:
Practical No: 06
30
Practical No – 6
Aim: Working with Circle CI for continuous integration.
Description:
Prerequisites
To follow along with the tutorial, a few things are required:
For simplicity, we will create a Flask application. Flask is a microframework for Python. For our
exercise, minimal knowledge of the framework is necessary.
First, create a project directory (folder) and cd into it. Type this into Terminal:
Next, open your favorite editor and create a hello.py file. Then, copy the following lines into that file:
from flask import
Flask app =
Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
Now it is time to create a requirements.txt file in our editor. Add the word Flask to the file and
save it.
Then, within the virtual environment, install the package by running:
The final command to run this application is:
FLASK_APP=hello.py flask run
31
Create a .circleci folder and inside of that create a config.yml file. Then, copy these lines into it:
version:
2 jobs:
build:
docker:
- image: circleci/python:3.6
steps:
- checkout - restore_cache: key:
deps1-{{ .Branch }}-{{ checksum
"requirements.txt" }} - run:
command: | python3 -m
venv venv .
venv/bin/activate pip
install -r
requirements.txt -
save_cache:
key: deps1-{{ .Branch }}-{{ checksum
"requirements.txt" }} paths: - "venv" - run:
name: Running tests
command: |
. venv/bin/activate
python3 tests.py -
store_artifacts:
path: test-reports/
destination:
python_ap
Pushing to GitHub
Using the philosophy of committing your code early and often, we should have initialized Git
earlier in this process, and we would have atomic commits. Because this tutorial is about
integration of CircleCI and GitHub, I intentionally put it on hold until now.
32
We can now commit our code by running the following commands:
git add
.
git commit -m "Initial
commit"
33
After creating your new repository, you will get to a page like this one:
Configuring CircleCI
Now that the repo is on GitHub, we can finalize the CI by configuring CircleCI. Head on over to the
CircleCI sign up page. Sign up for CircleCI with your GitHub account.
Once you are logged in, make sure that your personal GitHub account is active. If you are in several
GitHub organizations, one of them might be active. Just click the drop down menu (top left) and
select your GitHub username. Then, click Add Projects. The most recent project,
‘python_app’, is listed there.
34
Click Set up Project at the right side of the row that includes our project. On the redirected page, you
will notice the Next Steps section. Had we not had our own .circleci/config.yml file, we would have
started at No. 1. Because we do have the config.yml file, we can just scroll to No. 5 and click Start
building.
In the top right corner, click the Settings cog. Then click Projects on the left, and finally, python_app.
It is important that you become familiar with the settings that you can change for this project. I will
touch on what is relevant to us now.
35
In Advanced Settings, notice that Only build pull requests is turned off. This means that every push to
GitHub will run on CircleCI, including PRs. ReadME - status badge
Open your editor and create a README.md file. Copy and paste the following lines into this file:
README.md
# PYTHON APPLICATION
This Python application repo was created to showcase the integration
between GitHub and CircleCI.
[![CircleCI](https://circleci.com/gh/NdagiStanley/python_app.svg?
style=svg)](https://c ircleci.com/
gh/NdagiStanley/python_app)
git add .
git commit -m "Add
README" git push -u origin
add_readme
36
A successful build! Now, click Show all checks. Notice that the check is from CircleCI.
successful run. If you click Details, this will redirect you to the build
on CircleCI:
37
Notice that the favicon here also shows that the build is successful:
Conclusion
There you have it! We have enabled continuous integration with CircleCI.
Practical No: 07
Aim: Working with Kubernetes.
Kubernetes, or k8s, is an open-source platform that automates Linux container operations. It eliminates
many of the manual processes involved in deploying and scaling containerized applications. “In other
words, you can cluster together groups of hosts running Linux containers, and Kubernetes helps you
easily and efficiently manage those clusters.”
38
Add your user to the microk8s admin group
MicroK8s creates a group to enable seamless usage of commands which require admin privilege. Use
the following commands to join the group:
su - $USER
39
Turn on the services you want
40
Access the Kubernetes dashboard
microk8s dashboard-proxy
eyJhbGciOiJSUzI1NiIsImtpZCI6IkNqcUpFTmRfUkJNdko1RVVSUVBsdzVBZUpH
Ym9zUUxxb1phSDE4aGYwQncifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY
2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiO
iJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2Vjc
41
mV0Lm5hbWUiOiJkZWZhdWx0LXRva2VuLWtnaDR4Iiwia3ViZXJuZXRlcy5pby9zZ
XJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImRlZmF1bHQiLCJrd
WJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiO
iJkZTM2ZDJlZS1kNWY1LTRiMmEtYTgzMy04YWFjNGMxYjFmMzkiLCJzdWIiOiJze
XN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06ZGVmYXVsdCJ9.VrRWQF-
Lj9KP2BbbFCykbMh0O0RqvWvxHkavI4E23Au4nR1NCo3vEdwAhf_XVo8CpiwvXON
mjdVXk0jcroqq61LR04-
7firdj_uWnQMgFFFtTX8i150NX900uzSDO799VLG2UgZ-cWO1a0vRFREYdt-
LIQ2U56lsYgTdt5nKppau-Y07tFLvhF3KI_N6BllKfOVr_CtB6zJ1GDo29-
V2_MmY2DCTCE85VH3F6GZiph3uLp7Qv8SAOhzVl8e49VVrbfNL-
KWemBZhXdjd1X4L2xEh1ZJqY_nhmrN4MivTZE5yLqWIyUTY-
nxdiwB5tYG0YAyZ0oCXBEpSsgyVfhxOKw
Practical No: 08
Aim: Creating Microservice with ASP.NET Core.
42
Description:
Create a new ASP.NET Core project. I called mine HelloMicroservice (and the full source code is
available on GitHub for your reference
Step 1: Create a new solution
43
Step 2: Add docker-compose support
Right click on the project, and click “Add” and then “Container Orchestrator Support”.
Keep in mind that the sole purpose of this project is to start development for a proof of concept for
ASP.NET Core Microservices. Docker-compose is easier to deal with than Kubernetes for local
machine development. This is why I’m choosing the “Docker Compose” option,
even though I may eventually want to deploy to Kubernetes.
44
At this point, you can hit CTRL+F5 to run. Visual Studio will use Docker Compose to create an image of
your project and run it within Docker. Your browser should open automatically, and you’ll see
the standard “Welcome” screen
45
Step 3: Add database orchestration to docker-compose
Couchbase makes official container images available on Docker Hub. To use these images, lets add
another service under services: in the docker-compose.yml file:
46
Using wait-for-it is optional, but when you’re right in the middle of development, this
may save you some headaches. Finally, to make the ASP.NET Core project talk to Couchbase, I used the
Dependency Injection Extension from NuGet
47
Step 5: Using the database
Finally, let’s make sure that the ASP.NET Core application is able to communicate
with the database. I added a very simple Insert and Get to the HomeController Index method:
48
And now, we have the basics of ASP.NET Core Microservices in place. Hit CTRL+F5 to run the service.
When the browser opens, you should see something like this:
49