Skip to content

jsanthoshkiran/calculator-microservices

Repository files navigation

Calculator Microservices - DevOps Workshop

A hands-on DevOps workshop project demonstrating microservices architecture with containerization and orchestration.

Project Overview

This project implements a simple calculator system using microservices architecture:

  • API Gateway routes requests to individual services
  • 5 Microservices handle operations: Add, Subtract, Multiply, Divide

Architecture

┌─────────────────────────────────┐
│      API Gateway (Port 3000)    │
├─────────────────────────────────┤
    │        │        │        │
    ↓        ↓        ↓        ↓
  Add    Subtract  Multiply  Divide
 (3001)   (3002)    (3003)    (3004)

Local Development

Prerequisites

  • Node.js 18+
  • npm 9+
  • Docker Desktop
  • Kubernetes enabled in Docker Desktop

Running Services Locally (Parallel Terminals)

Terminal 1: Gateway

cd gateway
npm install
npm start

Terminal 2: Add Service

cd add-service
npm install
npm start

Terminal 3: Subtract Service

cd subtract-service
npm install
npm start

Terminal 4: Multiply Service

cd multiply-service
npm install
npm start

Terminal 5: Divide Service

cd divide-service
npm install
npm start

Testing Endpoints

Gateway Health:

curl http://localhost:3000/health

Gateway Info:

curl http://localhost:3000/info

Operations:

curl "http://localhost:3000/add?a=10&b=5"
curl "http://localhost:3000/subtract?a=10&b=3"
curl "http://localhost:3000/multiply?a=6&b=7"
curl "http://localhost:3000/divide?a=20&b=4"

Docker

Building Images

# Gateway
docker build -t jsanthoshkiran/calculator-gateway:v1 ./gateway
docker push jsanthoshkiran/calculator-gateway:v1

# Add Service
docker build -t jsanthoshkiran/calculator-add:v1 ./add-service
docker push jsanthoshkiran/calculator-add:v1

# Subtract Service
docker build -t jsanthoshkiran/calculator-subtract:v1 ./subtract-service
docker push jsanthoshkiran/calculator-subtract:v1

# Multiply Service
docker build -t jsanthoshkiran/calculator-multiply:v1 ./multiply-service
docker push jsanthoshkiran/calculator-multiply:v1

# Divide Service
docker build -t jsanthoshkiran/calculator-divide:v1 ./divide-service
docker push jsanthoshkiran/calculator-divide:v1

Running Containers

docker run -p 3001:3001 jsanthoshkiran/calculator-add:v1
docker run -p 3002:3002 jsanthoshkiran/calculator-subtract:v1
docker run -p 3003:3003 jsanthoshkiran/calculator-multiply:v1
docker run -p 3004:3004 jsanthoshkiran/calculator-divide:v1
docker run -p 3000:3000 -e ADD_SERVICE_URL=http://host.docker.internal:3001 jsanthoshkiran/calculator-gateway:v1

Kubernetes

Deployment

kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml

Verification

kubectl get deployments
kubectl get pods
kubectl get svc

Port Forward to Test

kubectl port-forward svc/calculator-gateway-service 3000:3000

Scaling

kubectl scale deployment calculator-add --replicas=5

Logs

kubectl logs -f deployment/calculator-gateway

CI/CD Pipeline

Jenkins pipeline automatically:

  1. Builds Docker images
  2. Runs tests
  3. Pushes to Docker Hub
  4. Deploys to Kubernetes --- For testing a trigger

Learning Outcomes

  • Microservices architecture
  • Docker containerization
  • Kubernetes orchestration
  • CI/CD pipeline automation
  • GitHub version control workflow
  • Production-ready deployment

About

A DevOps workshop project with microservices-based calculator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors