You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fully functional Snake Game built as a production-ready three-tier microservices application with JWT authentication, a complete DevSecOps CI/CD pipeline, containerized with Docker, and deployed on AWS EKS using Terraform and Helm. Includes full observability with Prometheus and Grafana.
Prometheus and Grafana are installed via Terraform using kube-prometheus-stack. ServiceMonitors scrape backend and auth-service automatically via label monitoring: enabled.
Apply custom dashboards and ServiceMonitors:
kubectl apply -k k8s-manifest/
☁️ Infrastructure — Terraform
What it provisions
Resource
Details
VPC
10.1.0.0/16 across 3 AZs (ap-south-1a/b/c)
EKS Cluster
Managed Kubernetes
Node Group
m7i-flex.large, ON_DEMAND, min 1 / desired 1 / max 2, 30GB
IAM Roles
Cluster role + node group role
OIDC Provider
For IRSA (IAM Roles for Service Accounts)
EBS CSI Driver
For PVC support with gp2 storage
ECR Repositories
frontend, backend, auth-service
kube-prometheus-stack
Prometheus + Grafana + Alertmanager (Helm)
Usage
cd infrastructure
terraform init
terraform plan
terraform apply # ~15 minutes
terraform destroy # when done — saves AWS credits
Register/Login → Auth Service → MongoDB (users)
← JWT token (7 day expiry)
Save Score → Backend validates JWT using shared JWT_SECRET
→ Extracts username from token payload
→ Saves score + username to MongoDB
Backend never calls Auth Service again after login.
JWT_SECRET must be identical in both services — stored in mongo-sec Secret.
🗄️ Database
Name:snakegame
Storage: EBS gp2 PVC (100Mi) via StatefulSet volumeClaimTemplates
Credentials: Kubernetes Secret mongo-sec
Collection
Fields
scores
score, username, userId, createdAt
users
username, password (bcrypt 10 rounds), createdAt
🔧 Kubernetes Resources
Resource
Name
Details
Namespace
three-tier-dev
App resources
Namespace
monitoring
Prometheus + Grafana
Deployment
frontend-deployment
Nginx + React
Deployment
backend-dep
Node.js API
Deployment
auth-dep
Auth microservice
StatefulSet
mongodb-deployment
MongoDB
Service
frontend-svc
ClusterIP — port 80
Service
backend-svc
ClusterIP — port 5000
Service
auth-svc
ClusterIP — port 4000
Service
mongodb-svc
Headless — port 27017
ConfigMap
backend-config
MONGO_URI, PORT
ConfigMap
auth-config
MONGO_URI, PORT
Secret
mongo-sec
MongoDB credentials + JWT_SECRET
PVC
mongodb-volume-claim
Auto-created by StatefulSet
Ingress
ingress
/ → frontend, /api → backend, /auth → auth
ServiceMonitor
backend-monitor
Prometheus scrape config
ServiceMonitor
auth-monitor
Prometheus scrape config
ConfigMap
grafana-dashboard
Custom dashboard JSON
🛡️ Security
Feature
Applied To
SonarQube analysis + quality gate
All three pipelines
Trivy image scanning HIGH/CRITICAL
All three pipelines
.trivyignore with documented CVEs
Backend, Auth service
bcrypt password hashing (10 rounds)
Auth service
JWT token auth (7d expiry)
Auth + Backend
seccompProfile: RuntimeDefault
All pods
allowPrivilegeEscalation: false
All containers
privileged: false
All containers
Credentials via Kubernetes Secret
MongoDB + JWT
IAM role on Jenkins EC2
No hardcoded AWS keys
ECR for image storage
No Docker Hub in production
📊 Resource Limits
Tier
Mem Request
Mem Limit
CPU Request
CPU Limit
Frontend
100Mi
100Mi
100m
200m
Backend
250Mi
250Mi
300m
500m
Auth Service
250Mi
250Mi
300m
500m
MongoDB
256Mi
512Mi
250m
500m
🔍 Health Checks
Tier
Type
Path
Readiness
Liveness
Frontend
HTTP GET
/ port 80
10s
15s
Backend
HTTP GET
/health port 5000
10s
15s
Auth Service
HTTP GET
/health port 4000
10s
15s
MongoDB
exec mongosh ping
—
30s (5 retries)
60s
🛑 Useful Commands
# Check everything
kubectl get all -n three-tier-dev
kubectl get all -n monitoring
# Stream logs
kubectl logs -f deployment/backend-dep -n three-tier-dev
kubectl logs -f deployment/auth-dep -n three-tier-dev
kubectl logs -f statefulset/mongodb-deployment -n three-tier-dev
# Restart deployment
kubectl rollout restart deployment/backend-dep -n three-tier-dev
# Apply with Kustomize
kubectl apply -k k8s-manifest/
# Helm status
helm status snake-game
helm history snake-game
# Port forward Grafana
kubectl port-forward svc/kube-prometheus-stack-grafana 3000:80 -n monitoring
# Port forward Prometheus
kubectl port-forward svc/kube-prometheus-stack-prometheus 9090:9090 -n monitoring
# Delete app
helm uninstall snake-game
kubectl delete namespace three-tier-dev
# Destroy AWS infra (save credits)cd infrastructure && terraform destroy