This detailed guide focuses on deploying the MERN E-Commerce Store source code (from https://github.com/HuXn-WebDev/MERN-E-Commerce-Store.git) with a modern DevOps pipeline involving Docker for containerization, Kubernetes for orchestration, Jenkins for CI/CD, and Prometheus for monitoringโpurpose-built for DevOps engineers to demonstrate deployment and operational practices.
Table of Contents
- Overview & Prerequisites
- Application Preparation
- Dockerization of MERN App
- Jenkins CI/CD Setup
- Kubernetes Deployment
- Prometheus Monitoring Setup
- Best Practices & Tips
- Troubleshooting and Future Enhancements
1. Overview & Prerequisites
Objective
Deploy a production-grade MERN (MongoDB, Express, React, Node.js) e-commerce app using DevOps best practices.
Prerequisites
- OS: Linux preferred (Windows WSL acceptable).
- Installed Tools:
- Docker & Docker Compose
- Kubernetes (Minikube or managed, e.g., EKS, GKE)
- kubectl CLI
- Jenkins (standalone or Dockerized)
- Prometheus and Grafana
- Git
- Knowledge Requirements:
- Familiarity with containerization, Kubernetes constructs, CI/CD principles, and service monitoring.
2. Application Preparation
Clone the Repository
git clone https://github.com/HuXn-WebDev/MERN-E-Commerce-Store.git cd MERN-E-Commerce-Store Review Source Structure
MERN-E-Commerce-Store/ backend/ frontend/ .env package.json README.md Environment Setup
- Set up a
.envfile in the backend directory with MongoDB URI, JWT secrets, and port. - Example snippet:
MONGO_URI=mongodb://mongo:27017/mernstore JWT_SECRET=your_jwt_secret PORT=5000 3. Dockerization of MERN App
Backend Dockerfile (backend/Dockerfile)
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . EXPOSE 5000 CMD ["npm", "start"] Frontend Dockerfile (frontend/Dockerfile)
FROM node:18-alpine as build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build FROM nginx:alpine COPY --from=build /app/build /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] Docker Compose for Local Testing (docker-compose.yml)
version: '3.8' services: mongo: image: mongo restart: always ports: - "27017:27017" volumes: - mongo-data:/data/db backend: build: ./backend ports: - "5000:5000" environment: - MONGO_URI=mongodb://mongo:27017/mernstore - JWT_SECRET=your_jwt_secret depends_on: - mongo frontend: build: ./frontend ports: - "3000:80" depends_on: - backend volumes: mongo-data: Test Docker Setup
docker-compose up --build Browse to http://localhost:3000 to verify the frontend and backend are connected.
4. Jenkins CI/CD Setup
Jenkins Installation Sample
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts Access Jenkins at http://localhost:8080.
Jenkins Pipeline Example (Jenkinsfile)
pipeline { agent any environment { DOCKERHUB_USER = 'yourdockerhubusername' REPO = 'mern-ecommerce-store' TAG = 'latest' } stages { stage('Checkout') { steps { git 'https://github.com/HuXn-WebDev/MERN-E-Commerce-Store.git' } } stage('Build Backend Image') { steps { sh 'docker build -t $DOCKERHUB_USER/$REPO-backend:$TAG ./backend' } } stage('Build Frontend Image') { steps { sh 'docker build -t $DOCKERHUB_USER/$REPO-frontend:$TAG ./frontend' } } stage('Push Images') { steps { withCredentials([string(credentialsId: 'dockerhub-pass', variable: 'PASS')]) { sh 'echo $PASS | docker login -u $DOCKERHUB_USER --password-stdin' sh 'docker push $DOCKERHUB_USER/$REPO-backend:$TAG' sh 'docker push $DOCKERHUB_USER/$REPO-frontend:$TAG' } } } stage('Deploy to Kubernetes') { steps { sh 'kubectl apply -f k8s/' } } } } - Store Docker registry credentials in Jenkins.
- Integrate GitHub webhooks for automation.
5. Kubernetes Deployment
Example Kubernetes Manifests (k8s/)
MongoDB Deployment and Service (k8s/mongo-deployment.yaml)
apiVersion: apps/v1 kind: Deployment metadata: name: mongo spec: replicas: 1 selector: matchLabels: app: mongo template: metadata: labels: app: mongo spec: containers: - name: mongo image: mongo ports: - containerPort: 27017 volumeMounts: - name: mongo-data mountPath: /data/db volumes: - name: mongo-data emptyDir: {} --- apiVersion: v1 kind: Service metadata: name: mongo spec: ports: - port: 27017 selector: app: mongo Backend Deployment and Service (k8s/backend-deployment.yaml)
apiVersion: apps/v1 kind: Deployment metadata: name: backend spec: replicas: 2 selector: matchLabels: app: backend template: metadata: labels: app: backend spec: containers: - name: backend image: yourdockerhubusername/mern-ecommerce-store-backend:latest ports: - containerPort: 5000 env: - name: MONGO_URI value: "mongodb://mongo:27017/mernstore" - name: JWT_SECRET value: "your_jwt_secret" --- apiVersion: v1 kind: Service metadata: name: backend spec: ports: - port: 5000 targetPort: 5000 selector: app: backend Frontend Deployment and Service (k8s/frontend-deployment.yaml)
apiVersion: apps/v1 kind: Deployment metadata: name: frontend spec: replicas: 2 selector: matchLabels: app: frontend template: metadata: labels: app: frontend spec: containers: - name: frontend image: yourdockerhubusername/mern-ecommerce-store-frontend:latest ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: frontend spec: ports: - port: 80 targetPort: 80 selector: app: frontend Ingress Example (k8s/ingress.yaml)
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: mernecommerce-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - host: your-domain.com http: paths: - path: / pathType: Prefix backend: service: name: frontend port: number: 80 Deploy to Kubernetes
kubectl apply -f k8s/ kubectl get pods,svc,ingress Access the app using Minikube IP or configured ingress.
6. Prometheus Monitoring Setup
Install Prometheus Stack
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update helm install prometheus prometheus-community/kube-prometheus-stack Enable Backend Metrics
Add Prometheus annotations to backend pod spec:
metadata: annotations: prometheus.io/scrape: 'true' prometheus.io/port: '5000' prometheus.io/path: '/metrics' Expose /metrics in your Node.js backend using a library like prom-client.
Access Grafana Dashboard
kubectl port-forward svc/prometheus-grafana 3000:80 Dashboard is accessible at http://localhost:3000 (login: admin/admin by default).
7. Best Practices & Tips
- Construct multi-stage Docker builds to optimize image layers.
- Place sensitive configuration in Kubernetes Secrets.
- Specify CPU/memory limits for each deployment.
- Ensure CI/CD runs all tests before deployments.
- Keep dependencies up-to-date and avoid unnecessary image layers.
- Use resource requests for optimal cluster utilization.
- Automate monitoring alerts using Prometheus Alertmanager.
8. Troubleshooting and Future Enhancements
- Inspect pod/container logs for failure diagnosis:
kubectl logs - Ensure Jenkins has access to your kubeconfig.
- Confirm Prometheus scrape targets are valid and reachable.
- Consider canary or blue/green deployment patterns.
- Integrate alert notifications to Slack or email via Alertmanager.
- Use custom Grafana dashboards for e-commerce KPIs (orders, sales, latency).
๐ ๏ธ Author & Community
This project is crafted by Harshhaa ๐ก.
Iโd love to hear your feedback! Feel free to share your thoughts.


Top comments (1)
That Github Repo is wrongly structured and hence not working !! But still managing to use it