Skip to content

aniasse/orchestrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Orchestrator - Kubernetes Microservices Deployment

Overview

This project deploys a microservices architecture on a K3s cluster with the following components:

  • inventory-db: PostgreSQL database for movies
  • billing-db: PostgreSQL database for orders
  • rabbitmq: Message broker for billing queue
  • inventory-app: Flask API for movie CRUD operations
  • billing-app: RabbitMQ consumer for processing billing orders
  • api-gateway: Flask API gateway routing requests

Architecture

                    +------------------+
                    |   API Gateway    |
                    |   (Port 3000)    |
                    +--------+---------+
                             |
           +-----------------+-----------------+
           |                                   |
           v                                   v
+------------------+               +----------------------+
|  Inventory App   |               |     RabbitMQ         |
|  (Port 8080)     |               |  (billing_queue)     |
+--------+---------+               +-----------+----------+
         |                                   |
         v                                   v
+------------------+               +------------------+
|  Inventory DB    |               |   Billing App     |
|  (PostgreSQL)    |               |                   |
+------------------+               +--------+-----------+
                                         |
                                         v
                                 +------------------+
                                 |   Billing DB     |
                                 |  (PostgreSQL)    |
                                 +------------------+

Prerequisites

  • Vagrant
  • VirtualBox
  • Docker
  • Docker Hub account
  • At least 8GB RAM available

Setup Instructions

1. Configure Docker Hub

Edit Manifests/*.yaml files and replace your-dockerhub-username with your actual Docker Hub username:

# Or export the variable
export DOCKER_USERNAME=your-username

2. Build and Push Docker Images

cd orchestrator
./Scripts/build-images.sh

3. Create the Cluster

./Scripts/orchestrator.sh create

This will:

  • Create 2 VMs (master and agent)
  • Install K3s on both nodes
  • Configure kubectl on the master node

4. Deploy Applications

./Scripts/orchestrator.sh deploy

This will deploy in order:

  1. Ingress Controller
  2. Secrets
  3. Databases (inventory-db, billing-db)
  4. RabbitMQ
  5. Applications (inventory-app, billing-app, api-gateway)
  6. Ingress

Usage

Check Status

./Scripts/orchestrator.sh status

Access the API

Once deployed, access the API Gateway at:

http://orchestrator.local/api/movies
http://orchestrator.local/api/billing

Or directly via the master node:

# Port forward to access the API
vagrant ssh master -- -L 3000:api-gateway:3000
# Then access http://localhost:3000

API Examples

# Create a movie
curl -X POST http://localhost:3000/api/movies \
  -H "Content-Type: application/json" \
  -d '{"title": "The Matrix", "description": "A sci-fi classic"}'

# Get all movies
curl http://localhost:3000/api/movies

# Search movies
curl "http://localhost:3000/api/movies?title=matrix"

# Create billing order
curl -X POST http://localhost:3000/api/billing \
  -H "Content-Type: application/json" \
  -d '{"user_id": "usr_123", "number_of_items": 3, "total_amount": 99.97}'

Manage Cluster

# Start VMs
./Scripts/orchestrator.sh start

# Stop VMs
./Scripts/orchestrator.sh stop

# Destroy cluster
./Scripts/orchestrator.sh destroy

# Delete deployments only
./Scripts/orchestrator.sh delete-deploy

Kubernetes Resources

Deployments (with HPA)

  • api-gateway: 1-3 replicas, CPU 60% trigger
  • inventory-app: 1-3 replicas, CPU 60% trigger

StatefulSets

  • inventory-db: PostgreSQL with persistent storage
  • billing-db: PostgreSQL with persistent storage
  • rabbitmq: RabbitMQ with persistent storage
  • billing-app: RabbitMQ consumer

Services

  • api-gateway: ClusterIP:3000
  • inventory-app: ClusterIP:8080
  • billing-app: ClusterIP:8080
  • inventory-db: ClusterIP:5432
  • billing-db: ClusterIP:5432
  • rabbitmq: ClusterIP:5672, 15672

Horizontal Pod Autoscaling

Both api-gateway and inventory-app are configured with:

  • Min replicas: 1
  • Max replicas: 3
  • CPU trigger: 60%

File Structure

orchestrator/
├── Vagrantfile                    # K3s cluster definition
├── Manifests/
│   ├── secrets.yaml              # K8s secrets
│   ├── ingress-controller.yaml  # Nginx ingress controller
│   ├── ingress.yaml             # API ingress
│   ├── inventory-db-statefulset.yaml
│   ├── billing-db-statefulset.yaml
│   ├── rabbitmq-statefulset.yaml
│   ├── inventory-app-deployment.yaml
│   ├── billing-app-statefulset.yaml
│   └── api-gateway-deployment.yaml
├── Scripts/
│   ├── orchestrator.sh          # Main cluster management
│   ├── build-images.sh          # Build and push Docker images
│   └── k3s-master.sh           # Master node setup (legacy)
│   └── k3s-agent.sh           # Agent node setup (legacy)
└── Dockerfiles/
    ├── api-gateway/
    ├── inventory-app/
    ├── inventory-db/
    ├── billing-app/
    ├── billing-db/
    └── rabbitmq/

Troubleshooting

Check Pod Logs

vagrant ssh master -- -t "sudo kubectl logs -n default <pod-name>"

Check Pod Status

vagrant ssh master -- -t "sudo kubectl get pods -A"

Restart a Deployment

vagrant ssh master -- -t "sudo kubectl rollout restart deployment/<deployment-name>"

Access RabbitMQ Management UI

# Port forward
vagrant ssh master -- -L 15672:rabbitmq:15672
# Access http://localhost:15672

Bonus Features

  • Kubernetes Dashboard deployment
  • Logging dashboard (e.g., Kibana/Grafana)
  • Cloud provider deployment (GKE/EKS/AKS)
  • CI/CD pipeline integration

About

Kubernetes microservices deployment with K3s

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors