Skip to content

๐Ÿ› ๏ธ Production-ready 3-tier MERN app deployed on Kubernetes with secrets, namespaces, and NodePort services for scalable microservice architecture.

License

Notifications You must be signed in to change notification settings

elonerajeev/3-Tier-App-K8s-Deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ 3-Tier-Architecture-App Deployment Using Kubernetes (Minikube+Helm+..)

Kubernetes Docker Minikube Mongo

Production-ready 3-tier application deployment showcasing modern container orchestration

๐Ÿ”ฅ Live Demo โ€ข ๐Ÿ“– Documentation โ€ข ๐Ÿ› ๏ธ Getting Started โ€ข ๐Ÿ’ผ Portfolio


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Project Overview

This project demonstrates enterprise-grade Kubernetes deployment by building a complete 3-tier application with modern container orchestration practices. The application showcases scalable microservices architecture with proper service mesh, persistent storage, and production-ready configurations.

๐ŸŽช What Makes This Special?

  • ๐Ÿ”„ Full Container Orchestration: Complete Kubernetes deployment with service discovery
  • ๐Ÿ—๏ธ Scalable Architecture: Independent scaling of frontend, backend, and database tiers
  • ๐Ÿ“Š Production Ready: Health checks, monitoring, and persistent storage
  • ๐Ÿ’ฐ Resource Optimized: Efficient resource allocation with Minikube deployment

๐Ÿ—๏ธ Architecture

Architecture Diagram


๐Ÿงฐ Technology Stack

Category Technologies
โ˜ธ๏ธ Container Orchestration Kubernetes, Minikube
๐Ÿณ Containerization Docker, Docker Compose
๐ŸŽจ Frontend Framework React.js, Vue.js, Nginx
โš™๏ธ Backend Services Node.js, Express.js, RESTful APIs
๐Ÿ—„๏ธ Database MongoDB Altas String
๐Ÿ“Š Monitoring Prometheus, Grafana, Health Checks
๐Ÿ”ง Configuration ConfigMaps, Environment Variables

โœจ Key Features

๐ŸŽฏ Kubernetes Native Architecture

  • ๐Ÿงฉ Microservices Design: Independently deployable and scalable tiers
  • ๐ŸŒ Service Discovery: Native Kubernetes DNS and service networking
  • ๐Ÿ”„ Auto-healing: Kubernetes controllers ensure desired state

๐Ÿš€ Production-Ready Deployment

  • โšก Rolling Updates: Zero-downtime deployments with rolling update strategy
  • ๐Ÿณ Multi-Container Pods: Sidecar patterns and init containers
  • ๐Ÿ“ก Load Balancing: Built-in service load balancing and traffic distribution
  • ๐Ÿ” Health Monitoring: Comprehensive liveness and readiness probes

๐Ÿ›ก๏ธ Security & Best Practices

  • ๐Ÿ” Secrets Management: Kubernetes secrets for sensitive data
  • ๐ŸŒ Network Security: Network policies and service mesh integration
  • ๐Ÿšช Access Control: RBAC with service accounts and role bindings
  • ๐Ÿ”’ Pod Security: Security contexts and non-root containers

๐Ÿ“Š Observability & Monitoring

  • ๐Ÿ“ˆ Metrics Collection: Prometheus integration for custom metrics
  • ๐Ÿ“Š Dashboard Visualization: Grafana dashboards for monitoring
  • ๐Ÿ” Logging: Centralized logging with structured log formats
  • ๐Ÿšจ Alerting: Alert manager integration for critical events

๐Ÿš€ Quick Start (Check Script In repo)

Prerequisites

# Required tools
kubectl version --client    # Kubernetes CLI >= 1.25.0
minikube version           # Minikube >= 1.28.0
docker --version          # Docker >= 20.10.0
git --version            # Git

1๏ธโƒฃ Clone & Setup

git clone https://github.com/elonerajeev/3-Tier-App-K8s-Deployment.git
cd 3-Tier-App-K8s-Deployment

4๏ธโƒฃ Deploy Application

# Deploy entire 3-tier application
make deploy
# or use the deployment script:
# chmod +x scripts/deploy.sh && ./scripts/deploy.sh

# Verify deployment
kubectl get pods -n mern-app(namespace)

5๏ธโƒฃ Access Application

# Get application URL
minikube service -n 3tier-app frontend --url
# or use port forwarding:
# kubectl port-forward -n 3tier-app service/frontend 3000:3000

๐Ÿ“ Project Structure

๐Ÿ“ฆ 3-Tier-App-K8s-Deployment/
โ”œโ”€โ”€ ๐ŸŽจ frontend/
โ”‚   โ”œโ”€โ”€ src/                         # React/Vue source code
โ”‚   โ”œโ”€โ”€ public/                      # Static assets
โ”‚   โ”œโ”€โ”€ Dockerfile                   # Frontend container image
โ”‚   โ”œโ”€โ”€ package.json                 # Dependencies
โ”‚   โ””โ”€โ”€ nginx.conf                   # Nginx configuration
โ”œโ”€โ”€ โš™๏ธ backend/
โ”‚   โ”œโ”€โ”€ src/                         # Node.js application
โ”‚   โ”‚   โ”œโ”€โ”€ controllers/             # API controllers
โ”‚   โ”‚   โ”œโ”€โ”€ models/                  # Data models
โ”‚   โ”‚   โ”œโ”€โ”€ routes/                  # API routes
โ”‚   โ”‚   โ””โ”€โ”€ middleware/              # Express middleware
โ”‚   โ”œโ”€โ”€ Dockerfile                   # Backend container image
โ”‚   โ”œโ”€โ”€ package.json                 # Dependencies
โ”‚   โ””โ”€โ”€ healthcheck.js               # Health check endpoint
|   โ””โ”€โ”€ index.js.js                  # main check endpoint
|
โ”œโ”€โ”€ โ˜ธ๏ธ k8s/
โ”‚   โ”œโ”€โ”€ namespace.yaml               # Kubernetes namespace
โ”‚   โ”œโ”€โ”€ frontend/
โ”‚   โ”‚   โ”œโ”€โ”€ deployment.yaml          # Frontend deployment
โ”‚   โ”‚   โ”œโ”€โ”€ service.yaml             # Frontend service
โ”‚   โ”‚   โ””โ”€โ”€ configmap.yaml           # Frontend configuration(Optional)
โ”‚   โ”œโ”€โ”€ backend/
โ”‚   โ”‚   โ”œโ”€โ”€ deployment.yaml          # Backend deployment
โ”‚   โ”‚   โ”œโ”€โ”€ service.yaml             # Backend service
โ”‚   โ”‚   โ”œโ”€โ”€ configmap.yaml           # Backend configuration(Optional)
โ”‚   โ”‚   โ””โ”€โ”€ secret.yaml              # Backend secrets(Optional)
โ”‚   โ”œโ”€โ”€ ingress/
โ”‚   โ”‚   โ””โ”€โ”€ ingress.yaml             # Ingress controller(Optional)
โ”‚   โ””โ”€โ”€ monitoring/
โ”‚       โ”œโ”€โ”€ prometheus.yaml          # Prometheus configuration
โ”‚       โ””โ”€โ”€ grafana.yaml             # Grafana dashboards
โ”œโ”€โ”€ ๐Ÿ› ๏ธ scripts/
โ”‚   โ”œโ”€โ”€ setup-minikube.sh            # Minikube setup script
โ”‚   โ”œโ”€โ”€ deploy.sh                    # Deployment automation
โ”‚   โ”œโ”€โ”€ cleanup.sh                   # Resource cleanup
โ”‚   โ””โ”€โ”€ port-forward.sh              # Port forwarding helper
โ”œโ”€โ”€ ๐Ÿ“Š monitoring/
โ”‚   โ”œโ”€โ”€ dashboards/                  # Grafana dashboards
โ”‚   โ”œโ”€โ”€ alerts/                      # Alert configurations
โ”‚   โ””โ”€โ”€ prometheus.yml               # Prometheus config
โ”œโ”€โ”€ ๐Ÿ”ง configs/
โ”‚   โ”œโ”€โ”€ nginx.conf                   # Nginx configurations
โ”‚   โ””โ”€โ”€ app.conf                     # Application configurations
โ”œโ”€โ”€ ๐Ÿ“– docs/
โ”‚   โ”œโ”€โ”€ DEPLOYMENT.md                # Deployment guide
โ”‚   โ”œโ”€โ”€ ARCHITECTURE.md              # Architecture documentation
โ”‚   โ””โ”€โ”€ TROUBLESHOOTING.md           # Troubleshooting guide
โ”œโ”€โ”€ Makefile                         # Automation commands
โ””โ”€โ”€ docker-compose.yml               # Local development setup

๐Ÿ”„ Deployment Pipeline

Deployment Workflow (Will Do In Fature With CICD Pipeline)

# Automated Deployment Process
stages:
  - ๐Ÿ” validate:
      - syntax-check
      - security-scan
  - ๐Ÿ—๏ธ build:
      - docker-build
      - image-push
  - ๐Ÿงช test:
      - unit-tests
      - integration-tests
  - ๐Ÿš€ deploy:
      - k8s-deployment
      - health-check

Deployment Stages

Stage Action Status
๐Ÿ” Validation YAML lint and security scan โœ… Active
๐Ÿ—๏ธ Build Docker image creation โœ… Active
๐Ÿงช Test Unit and integration tests โœ… Active
๐Ÿ“ค Registry Push to container registry โœ… Active
๐Ÿš€ Deploy Kubernetes deployment โœ… Active
โœ… Verify Health check validation โœ… Active

๐Ÿ’ก Implementation Highlights

๐Ÿ—๏ธ Kubernetes Deployment Configuration

# Example: Backend Deployment with Health Checks

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-deployment
  namespace: mern-app
  labels:
    app: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: backend-container
          image: elonerajeev/myapp-backend:v1
          ports:
            - containerPort: 5000
          envFrom:
            - secretRef:
                name: backend-secret

๐Ÿณ Optimized Multi-Stage Docker Build

# Frontend Production Build
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force
COPY . .
RUN npm run build

FROM nginx:alpine AS runtime
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

๐Ÿ”„ Automated Deployment Script (Full Script In Available In Repo)

#!/bin/bash

set -e
set -o pipefail

echo "๐Ÿš€ Starting 3-Tier Kubernetes Deployment..."

# Navigate to k8s manifests directory
if [ ! -d "k8s-deployment/manifest" ]; then
  echo "โŒ Directory 'k8s-deployment/manifest' not found!"
  exit 1
fi

cd k8s-deployment/manifest

# ======================
# Create Namespace
# ======================
echo "๐Ÿ“ Creating Namespace..."
if [ -f namespace.yaml ]; then
  kubectl apply -f namespace.yaml
else
  echo "โŒ namespace.yaml file not found!"
  exit 1
fi

# ======================
# Deploy Backend
# ======================
echo "โš™๏ธ Deploying Backend..."
kubectl apply -f backend/deployment.yaml
kubectl apply -f backend/service.yaml

๐ŸŽฏ Challenges & Solutions

๐Ÿ”ง Kubernetes Challenges
Challenge Solution Impact
Service Discovery Kubernetes DNS and service networking โœ… Resolved
Resource Management Resource requests and limits โšก Performance
Health Monitoring Liveness and readiness probes ๐Ÿ” Reliability
๐Ÿš€ Container Challenges
Challenge Solution Impact
Image Size Optimization Multi-stage Docker builds ๐Ÿš€ Performance
Configuration Management ConfigMaps and Secrets ๐Ÿ” Security
Inter-service Communication Service mesh and networking ๐ŸŒ Connectivity
Rolling Updates Kubernetes deployment strategies ๐Ÿ”„ Zero-downtime

๐Ÿ“ˆ Monitoring & Observability (Working ....)

๐Ÿ“Š Application Metrics Dashboard

# Access Prometheus metrics
curl http://localhost:9090/metrics

# Grafana Dashboard
kubectl port-forward -n monitoring service/grafana 3000:3000
# Access: http://localhost:3000

Key Metrics Monitored

  • ๐ŸŽฏ Application Performance: Response time, throughput, error rates
  • ๐Ÿ“Š Resource Utilization: CPU, memory, disk usage per pod
  • ๐ŸŒ Network Metrics: Request/response latency, connection counts
  • ๐Ÿ—„๏ธ Database Performance: Query performance, connection pools

Monitoring Stack

  • ๐Ÿ“Š Prometheus: Metrics collection and alerting
  • ๐Ÿ“ˆ Grafana: Visualization dashboards
  • ๐Ÿ” Kubernetes Dashboard: Cluster monitoring
  • ๐Ÿ“ฑ AlertManager: Alert notifications

๐Ÿ”ฎ Future Roadmap

Phase 1: Enhanced Security ๐Ÿ›ก๏ธ

  • Add network policies
  • Integrate Kubernetes secrets management

Phase 2: Advanced Features ๐Ÿš€

  • Horizontal Pod Autoscaling (HPA)
  • Blue-green deployment strategy
  • Canary deployments

Phase 3: Production Readiness ๐Ÿญ

  • Multi-cluster deployment
  • GitOps with ArgoCD

Phase 4: Cloud Migration โ˜๏ธ

  • EKS/GKE/AKS deployment
  • Terraform for infrastructure
  • CI/CD with GitHub Actions

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

๐Ÿ”ง Development Setup

# Fork the repository
git clone https://github.com/your-username/3-Tier-App-K8s-Deployment.git

# Create feature branch
git checkout -b feature/your-feature-name

# Make changes and test
make test

# Submit pull request

๐Ÿ“ Contribution Guidelines

  • Follow Kubernetes best practices
  • Write comprehensive tests
  • Update documentation
  • Use meaningful commit messages
  • Ensure security standards

๐Ÿ‘จโ€๐Ÿ’ป Author : elonerajeev

Rajeev Kumar Kubernetes Specialist & DevOps Engineer

Portfolio LinkedIn GitHub Email

"Orchestrating containers and building scalable cloud-native applications"


๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License - Feel free to use this project for learning and development!

๐ŸŒŸ If you found this project helpful, please give it a star!

GitHub stars GitHub forks

Made with โค๏ธ and โ˜• by Rajeev Kumar


๐Ÿš€ Ready to deploy your 3-tier application on Kubernetes?

Get Started Now โ€ข View Architecture โ€ข Join Community

About

๐Ÿ› ๏ธ Production-ready 3-tier MERN app deployed on Kubernetes with secrets, namespaces, and NodePort services for scalable microservice architecture.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published