Skip to content

Full-stack microservices application with Kubernetes deployment

Notifications You must be signed in to change notification settings

sultan101004/22i0637_MLOPs_A2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Full-Stack Microservices Application with Authentication

A complete microservices architecture demonstrating modern DevOps practices with containerization, orchestration, and deployment on Kubernetes/Minikube.

Architecture

🎯 Project Overview

This project implements a production-ready microservices application featuring:

  • Frontend: React SPA with responsive UI for auth flows
  • Backend: Node.js REST API with protected endpoints
  • Auth Service: Dedicated microservice for authentication (JWT-based)
  • Database: PostgreSQL with persistent storage
  • Containerization: Docker with multi-stage builds
  • Orchestration: Kubernetes manifests with 3 replicas per service
  • Security: Password hashing (bcrypt), JWT tokens, secrets management

πŸ“ Project Structure

fullstack-microservices/
β”œβ”€β”€ frontend/                   # React application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/        # Login, Signup, ForgotPassword, etc.
β”‚   β”‚   β”œβ”€β”€ App.js
β”‚   β”‚   └── index.js
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ nginx.conf
β”‚   └── package.json
β”œβ”€β”€ backend/                    # Backend REST API
β”‚   β”œβ”€β”€ server.js
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ package.json
β”‚   └── README.md
β”œβ”€β”€ auth-service/              # Authentication microservice
β”‚   β”œβ”€β”€ server.js
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ package.json
β”‚   └── README.md
β”œβ”€β”€ db/                        # Database initialization
β”‚   β”œβ”€β”€ init.sql
β”‚   └── README.md
β”œβ”€β”€ k8s/                       # Kubernetes manifests
β”‚   β”œβ”€β”€ namespace.yaml
β”‚   β”œβ”€β”€ configmap.yaml
β”‚   β”œβ”€β”€ secrets.yaml
β”‚   β”œβ”€β”€ pv-pvc.yaml
β”‚   β”œβ”€β”€ db-deployment.yaml
β”‚   β”œβ”€β”€ auth-deployment.yaml
β”‚   β”œβ”€β”€ backend-deployment.yaml
β”‚   β”œβ”€β”€ frontend-deployment.yaml
β”‚   β”œβ”€β”€ ingress.yaml
β”‚   └── kustomization.yaml
β”œβ”€β”€ docs/                      # Documentation
β”‚   β”œβ”€β”€ deployment-guide.md
β”‚   β”œβ”€β”€ demo-script.md
β”‚   └── architecture-diagram.png
β”œβ”€β”€ scripts/                   # Automation scripts
β”‚   β”œβ”€β”€ demo-test.sh
β”‚   β”œβ”€β”€ build-images.sh
β”‚   └── deploy-k8s.sh
β”œβ”€β”€ docker-compose.yml         # Local development
└── README.md                  # This file

✨ Features

Authentication

  • βœ… User signup with validation
  • βœ… Login with JWT access/refresh tokens
  • βœ… Forgot password with secure token generation
  • βœ… Reset password with token verification
  • βœ… Password hashing with bcrypt (10 rounds)
  • βœ… Token-based stateless authentication

Microservices Architecture

  • βœ… Service isolation with clear boundaries
  • βœ… Inter-service communication via HTTP
  • βœ… Independent scaling (3 replicas each)
  • βœ… Health checks and readiness probes
  • βœ… Configuration via ConfigMaps and Secrets

DevOps & Deployment

  • βœ… Dockerfiles with multi-stage builds
  • βœ… Docker Compose for local development
  • βœ… Kubernetes manifests with best practices
  • βœ… PersistentVolume for database
  • βœ… NodePort services for external access
  • βœ… Resource requests and limits
  • βœ… Liveness and readiness probes

πŸš€ Quick Start

Prerequisites

  • Docker (20.10+)
  • Docker Compose (1.29+)
  • Minikube (1.30+)
  • kubectl (1.26+)
  • Node.js 18+ (for local development)

Option 1: Docker Compose (Recommended for Local Dev)

# Clone the repository
cd fullstack-microservices

# Start all services
docker compose up --build

# Access the application
# Frontend: http://localhost:3000
# Auth Service: http://localhost:3001
# Backend: http://localhost:5000

Test the application:

# Signup
curl -X POST http://localhost:3001/signup \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe","email":"john@example.com","password":"SecurePass123"}'

# Login
curl -X POST http://localhost:3001/login \
  -H "Content-Type: application/json" \
  -d '{"email":"john@example.com","password":"SecurePass123"}'

# Get profile (use token from login)
TOKEN="<access-token>"
curl -H "Authorization: Bearer $TOKEN" http://localhost:5000/profile

Option 2: Kubernetes on Minikube

See detailed guide in docs/deployment-guide.md

# 1. Start Minikube
minikube start --cpus=4 --memory=8192

# 2. Build and load images
eval $(minikube docker-env)
docker build -t frontend:latest ./frontend
docker build -t backend:latest ./backend
docker build -t auth-service:latest ./auth-service

# 3. Deploy to Kubernetes
kubectl apply -f k8s/

# 4. Check deployment
kubectl get pods -n microservices

# 5. Access frontend
minikube service frontend-service -n microservices

# 6. Get Minikube IP for API access
minikube ip

πŸ”§ Configuration

Environment Variables

Auth Service (.env):

PORT=3001
DB_HOST=localhost
DB_PORT=5432
DB_NAME=authdb
DB_USER=postgres
DB_PASSWORD=postgres
JWT_SECRET=your-super-secret-jwt-key-change-in-production
JWT_REFRESH_SECRET=your-refresh-secret-key-change-in-production

Backend (.env):

PORT=5000
DB_HOST=localhost
DB_PORT=5432
DB_NAME=authdb
DB_USER=postgres
DB_PASSWORD=postgres
AUTH_SERVICE_URL=http://localhost:3001

Frontend (.env):

REACT_APP_AUTH_SERVICE_URL=http://localhost:3001
REACT_APP_BACKEND_SERVICE_URL=http://localhost:5000

πŸ“Š API Endpoints

Auth Service (Port 3001)

Method Endpoint Description Auth Required
POST /signup Register new user No
POST /login Login and get tokens No
POST /forgot-password Request password reset No
POST /reset-password Reset password with token No
POST /verify-token Verify JWT token No
POST /refresh-token Get new access token No
GET /health Health check No

Backend Service (Port 5000)

Method Endpoint Description Auth Required
GET /profile Get user profile Yes
PUT /profile Update profile Yes
GET /users List all users Yes
GET /public-info Public endpoint No
GET /health Health check No

Frontend (Port 3000/80)

  • /login - Login page
  • /signup - Signup page
  • /forgot-password - Password recovery
  • /reset-password - Password reset with token
  • /dashboard - User dashboard (protected)

πŸ§ͺ Testing

Automated Tests

# Run demo test script
./scripts/demo-test.sh

# Or run individual service tests
cd auth-service && npm test
cd backend && npm test
cd frontend && npm test

Manual Testing

See docs/demo-script.md for step-by-step testing instructions.

🎬 Demo Video

Follow the script in docs/demo-script.md to record a demo showing:

  1. Starting Minikube
  2. Building and loading images
  3. Deploying with kubectl
  4. Showing 3 replicas running
  5. Testing signup/login flows
  6. Making authenticated API calls
  7. Viewing data in dashboard

πŸ“ˆ Monitoring & Health Checks

Each service exposes a /health endpoint:

# Docker Compose
curl http://localhost:3001/health  # Auth
curl http://localhost:5000/health  # Backend

# Kubernetes (get NodePort first)
MINIKUBE_IP=$(minikube ip)
curl http://$MINIKUBE_IP:30001/health  # Auth
curl http://$MINIKUBE_IP:30000/health  # Backend

πŸ› οΈ Development

Local Development (without Docker)

# Terminal 1: Start PostgreSQL
docker run -d -p 5432:5432 \
  -e POSTGRES_DB=authdb \
  -e POSTGRES_PASSWORD=postgres \
  postgres:15-alpine

# Terminal 2: Auth Service
cd auth-service
npm install
npm run dev

# Terminal 3: Backend
cd backend
npm install
npm run dev

# Terminal 4: Frontend
cd frontend
npm install
npm start

Database Access

# Docker Compose
docker exec -it postgres-db psql -U postgres -d authdb

# Kubernetes
kubectl port-forward -n microservices svc/postgres-service 5432:5432
psql -h localhost -U postgres -d authdb

πŸ”’ Security Notes

For Production

  1. Change all default secrets in .env and Kubernetes secrets
  2. Use external secret managers: Vault, AWS Secrets Manager, etc.
  3. Enable HTTPS with proper TLS certificates
  4. Implement rate limiting on auth endpoints
  5. Use httpOnly cookies instead of localStorage for tokens
  6. Add CORS with specific origins (not wildcard)
  7. Enable database SSL connections
  8. Implement audit logging
  9. Use network policies to restrict pod-to-pod communication
  10. Regular security updates and dependency scanning

Current Demo Limitations

⚠️ This is a demo application. Do NOT use in production without:

  • Changing all default passwords and secrets
  • Implementing proper secret management
  • Adding rate limiting and DDoS protection
  • Using HTTPS everywhere
  • Implementing proper logging and monitoring
  • Adding comprehensive error handling
  • Implementing database backups
  • Adding CI/CD pipelines with security scanning

πŸ“ Architecture

Service Communication Flow

User β†’ Frontend (React SPA)
         ↓
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
    ↓         ↓
Auth Service  Backend Service
    ↓         ↓
    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
         ↓
    PostgreSQL

Authentication Flow

  1. User submits credentials to Auth Service
  2. Auth Service validates and returns JWT tokens
  3. Frontend stores tokens (localStorage in demo)
  4. Frontend sends token in Authorization header
  5. Backend verifies token with Auth Service
  6. Backend returns protected data

πŸŽ“ Learning Resources

This project demonstrates:

  • Microservices Architecture: Service isolation, API design
  • Containerization: Docker, multi-stage builds, optimization
  • Orchestration: Kubernetes deployments, services, scaling
  • Authentication: JWT tokens, password hashing, secure flows
  • DevOps: CI/CD-ready, infrastructure as code
  • Best Practices: Health checks, resource limits, secrets management

πŸ› Troubleshooting

Docker Compose Issues

# View logs
docker compose logs -f [service-name]

# Restart services
docker compose restart

# Clean restart
docker compose down -v
docker compose up --build

Kubernetes Issues

# Check pod status
kubectl get pods -n microservices

# View logs
kubectl logs -n microservices <pod-name>

# Describe pod
kubectl describe pod -n microservices <pod-name>

# Check events
kubectl get events -n microservices --sort-by='.lastTimestamp'

Common Issues

  1. ImagePullBackOff: Ensure images are built and loaded into Minikube
  2. CrashLoopBackOff: Check logs for errors, verify DB connectivity
  3. Connection refused: Ensure services are using correct service names
  4. 401 Unauthorized: Verify token is valid and not expired

🀝 Contributing

Contributions welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

βœ… Acceptance Criteria Checklist

  • Complete frontend with Signup, Login, Forgot Password, Dashboard
  • Backend service with protected endpoints
  • Separate auth microservice with JWT implementation
  • PostgreSQL database with persistent storage
  • Dockerfiles for all services
  • docker-compose.yml for local development
  • Kubernetes manifests with 3 replicas
  • PersistentVolume/PersistentVolumeClaim for database
  • ConfigMaps and Secrets
  • Health checks and resource limits
  • NodePort services for external access
  • Documentation (README, deployment guide, demo script)
  • Test scripts for automated validation
  • Architecture diagram
  • Security best practices (bcrypt, JWT, secrets)

πŸ“ž Support

For issues or questions:

  • Create an issue in the repository
  • Check existing documentation
  • Review logs for error messages

Built with ❀️ for learning microservices, Docker, and Kubernetes

About

Full-stack microservices application with Kubernetes deployment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published