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
+------------------+
| API Gateway |
| (Port 3000) |
+--------+---------+
|
+-----------------+-----------------+
| |
v v
+------------------+ +----------------------+
| Inventory App | | RabbitMQ |
| (Port 8080) | | (billing_queue) |
+--------+---------+ +-----------+----------+
| |
v v
+------------------+ +------------------+
| Inventory DB | | Billing App |
| (PostgreSQL) | | |
+------------------+ +--------+-----------+
|
v
+------------------+
| Billing DB |
| (PostgreSQL) |
+------------------+
- Vagrant
- VirtualBox
- Docker
- Docker Hub account
- At least 8GB RAM available
Edit Manifests/*.yaml files and replace your-dockerhub-username with your actual Docker Hub username:
# Or export the variable
export DOCKER_USERNAME=your-usernamecd orchestrator
./Scripts/build-images.sh./Scripts/orchestrator.sh createThis will:
- Create 2 VMs (master and agent)
- Install K3s on both nodes
- Configure kubectl on the master node
./Scripts/orchestrator.sh deployThis will deploy in order:
- Ingress Controller
- Secrets
- Databases (inventory-db, billing-db)
- RabbitMQ
- Applications (inventory-app, billing-app, api-gateway)
- Ingress
./Scripts/orchestrator.sh statusOnce 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# 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}'# 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-deployapi-gateway: 1-3 replicas, CPU 60% triggerinventory-app: 1-3 replicas, CPU 60% trigger
inventory-db: PostgreSQL with persistent storagebilling-db: PostgreSQL with persistent storagerabbitmq: RabbitMQ with persistent storagebilling-app: RabbitMQ consumer
api-gateway: ClusterIP:3000inventory-app: ClusterIP:8080billing-app: ClusterIP:8080inventory-db: ClusterIP:5432billing-db: ClusterIP:5432rabbitmq: ClusterIP:5672, 15672
Both api-gateway and inventory-app are configured with:
- Min replicas: 1
- Max replicas: 3
- CPU trigger: 60%
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/
vagrant ssh master -- -t "sudo kubectl logs -n default <pod-name>"vagrant ssh master -- -t "sudo kubectl get pods -A"vagrant ssh master -- -t "sudo kubectl rollout restart deployment/<deployment-name>"# Port forward
vagrant ssh master -- -L 15672:rabbitmq:15672
# Access http://localhost:15672- Kubernetes Dashboard deployment
- Logging dashboard (e.g., Kibana/Grafana)
- Cloud provider deployment (GKE/EKS/AKS)
- CI/CD pipeline integration