Deployment of MedusaJS V2 Ecommerce Backend on AKS (Azure Kubernetes Service)

By | November 7, 2025

This project demonstrates a production-like deployment of a MedusaJS v2 ecommerce backend using DockerJenkins CI/CDAzure Kubernetes Service (AKS), and PostgreSQL. The backend exposes REST APIs and an admin panel for managing ecommerce operations.


๐Ÿ”ง Tech Stack

  • Backend: MedusaJS v2
  • Database: PostgreSQL (containerized)
  • CI/CD: Jenkins (Pipeline-based deployment)
  • Containerization: Docker & Docker Compose
  • Orchestration: Kubernetes (AKS)
  • Cloud: Microsoft Azure
  • Others: Helm (optional), kubectl, Azure CLI

๐Ÿ“ Project Structure

MedusajsV2/
โ”‚
โ”œโ”€โ”€ k8s/                    # Kubernetes YAML files
โ”‚   โ”œโ”€โ”€ deployment.yaml
โ”‚   โ”œโ”€โ”€ service.yaml
โ”‚   โ””โ”€โ”€ postgres.yaml
โ”‚
โ”œโ”€โ”€ jenkins/
โ”‚   โ””โ”€โ”€ Jenkinsfile         # Jenkins CI/CD pipeline script
โ”‚
โ”œโ”€โ”€ Dockerfile              # Docker image for MedusaJS backend
โ”œโ”€โ”€ docker-compose.yml      # Local development setup
โ””โ”€โ”€ README.md               # This file

๐Ÿš€ Features

  • CI/CD pipeline triggered via Jenkins
  • Deployment on AKS using kubectl
  • External LoadBalancer to access Medusa Admin UI
  • Logs and service monitoring with kubectl
  • Secure PostgreSQL with volume persistence
  • Easily scalable & production-ready

๐Ÿ› ๏ธ Setup & Deployment

1. Clone the Repo

git clone https://github.com/jaspreet237/MedusajsV2.git
cd MedusajsV2

2. Build Docker Images

docker build -t medusa-app .
docker-compose up -d

3. Push to Docker Hub

docker tag medusa-app <your-dockerhub-username>/medusa-app
docker push <your-dockerhub-username>/medusa-app

4. Create AKS Cluster (Optional: if not already created)

az aks create --resource-group rg-aks-dev --name my-aks-cluster --node-count 1 --generate-ssh-keys
az aks get-credentials --resource-group rg-aks-dev --name my-aks-cluster

5. Apply Kubernetes Manifests

kubectl apply -f k8s/postgres.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml

6. Access Application

Check external IP:

kubectl get svc medusa-service

Visit:

http://<EXTERNAL-IP>:9000/app/login

๐Ÿงช Create Admin User (Inside Pod)

kubectl exec -it <medusa-pod-name> -- yarn medusa user -e admin@mail.com -p password

๐Ÿงฐ Jenkins CI/CD Setup

  • Pipeline includes steps to:
    • Clone repo
    • Build Docker image
    • Push to Docker Hub
    • Apply Kubernetes manifests

Example Jenkinsfile is included underย jenkins/.

๐Ÿ’ฐ Azure AKS Cost Estimation (For MedusaJS V2 Deployment)

Deploying MedusaJS v2 on Azure Kubernetes Service (AKS) involves multiple Azure resources that contribute to the total monthly cost. The following breakdown provides an approximate cost structure for running a single production-like MedusaJS backend with PostgreSQL.

โš™๏ธ Resource Breakdown (1-Node Setup)

ComponentResource TypeEstimated Monthly Cost (INR/USD)Description
AKS Cluster NodeStandard_B2s (2 vCPU, 4 GB RAM)โ‚น2,000 / $25Runs MedusaJS and PostgreSQL pods
AKS Control PlaneManaged by AzureFreeControl plane is free for 1st cluster
Azure Container Registry (Optional)Basic Tierโ‚น350 / $5Stores Docker images for deployment
Managed Disk (Persistent Storage)20 GB Premium SSDโ‚น300 / $4Persistent volume for PostgreSQL
Azure Load BalancerStandard SKUโ‚น700 / $9Provides external access to MedusaJS API
Public IP (Static)1 Static IPโ‚น250 / $3Assigned to the LoadBalancer service
Bandwidth / Egress Data~50 GB outbound/monthโ‚น500 / $6Depends on app traffic and usage

๐ŸŸฉ Estimated Monthly Total: ~ โ‚น4,100 โ€“ โ‚น5,000 (~$50 โ€“ $60 USD)

๐Ÿ’ก This estimate assumes 24/7 uptime with low-to-medium traffic. For development or testing environments, cost can be reduced by using Spot instances or scaling down node count.


๐Ÿ“ˆ Scaling Cost for Additional Applications or Pods

If you want to deploy multiple MedusaJS backends or microservices, the cost scales linearly based on pod and node utilization.

ScenarioExampleApprox. Cost Impact
2 MedusaJS Apps2 Deployments sharing same AKS Node+โ‚น1,000 / +$12
3โ€“4 MedusaJS AppsRequires 2nd AKS Node+โ‚น2,000 / +$25
Horizontal Pod AutoscalerScales automatically with loadBased on CPU usage and node addition

๐Ÿ”น Each new node adds approximately โ‚น2,000โ€“โ‚น2,500 ($25โ€“$30) per month.
๐Ÿ”น Storage and bandwidth usage also increase proportionally.


๐Ÿงฎ How to Estimate Exact Cost

You can calculate your precise AKS expenses using the Azure Pricing Calculator:

๐Ÿ”— https://azure.microsoft.com/en-us/pricing/calculator

To use it:

  1. Add Azure Kubernetes Service
  2. Select VM Size (e.g., B2s or D2s_v3) and region
  3. Include Storage, Bandwidth, and Public IP
  4. Compare between Dev/Test and Production usage levels

๐Ÿช„ Cost Optimization Tips

  • Use B-series VMs for development (low-cost burstable instances)
  • Enable node auto-scaling to reduce idle costs
  • Schedule cluster shutdown for non-production workloads
  • Store Docker images in Azure Container Registry (Basic tier)
  • Monitor and right-size resources using Azure Advisor

๐Ÿ“Œ Future Enhancements

  • Implement Ingress Controller (Nginx or Traefik)
  • Enable TLS with Let’s Encrypt
  • Add Redis for caching & job queue
  • Configure Horizontal Pod Autoscaler
  • Enable Role-Based Access Control (RBAC)
  • Integrate monitoring (Prometheus + Grafana)

๐Ÿง  What You Can Learn From This Project

  • Real-world AKS deployment
  • End-to-end DevOps pipeline using Jenkins
  • Secure and scalable Kubernetes practices
  • Practical MedusaJS backend usage

๐Ÿค Contributing

Pull requests and stars are welcome! For major changes, please open an issue first.

One thought on “Deployment of MedusaJS V2 Ecommerce Backend on AKS (Azure Kubernetes Service)

  1. Myallcodes

    Pull requests and stars are welcome! For major changes, please open an issue first.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *