{"id":268,"date":"2025-07-25T08:04:03","date_gmt":"2025-07-25T08:04:03","guid":{"rendered":"https:\/\/myallcodes.in\/?p=268"},"modified":"2025-11-07T05:27:50","modified_gmt":"2025-11-07T05:27:50","slug":"deployment-of-medusajs-v2-ecommerce-backend-on-aks-azure-kubernetes-service","status":"publish","type":"post","link":"https:\/\/myallcodes.in\/index.php\/2025\/07\/25\/deployment-of-medusajs-v2-ecommerce-backend-on-aks-azure-kubernetes-service\/","title":{"rendered":"Deployment of MedusaJS V2 Ecommerce Backend on AKS (Azure Kubernetes Service)"},"content":{"rendered":"\n<p>This project demonstrates a production-like deployment of a&nbsp;<strong>MedusaJS v2 ecommerce backend<\/strong>&nbsp;using&nbsp;<strong>Docker<\/strong>,&nbsp;<strong>Jenkins CI\/CD<\/strong>,&nbsp;<strong>Azure Kubernetes Service (AKS)<\/strong>, and&nbsp;<strong>PostgreSQL<\/strong>. The backend exposes REST APIs and an admin panel for managing ecommerce operations.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd27 Tech Stack<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-tech-stack\"><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Backend<\/strong>: MedusaJS v2<\/li>\n\n\n\n<li><strong>Database<\/strong>: PostgreSQL (containerized)<\/li>\n\n\n\n<li><strong>CI\/CD<\/strong>: Jenkins (Pipeline-based deployment)<\/li>\n\n\n\n<li><strong>Containerization<\/strong>: Docker &amp; Docker Compose<\/li>\n\n\n\n<li><strong>Orchestration<\/strong>: Kubernetes (AKS)<\/li>\n\n\n\n<li><strong>Cloud<\/strong>: Microsoft Azure<\/li>\n\n\n\n<li><strong>Others<\/strong>: Helm (optional), kubectl, Azure CLI<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcc1 Project Structure<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-project-structure\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MedusajsV2\/\n\u2502\n\u251c\u2500\u2500 k8s\/                    # Kubernetes YAML files\n\u2502   \u251c\u2500\u2500 deployment.yaml\n\u2502   \u251c\u2500\u2500 service.yaml\n\u2502   \u2514\u2500\u2500 postgres.yaml\n\u2502\n\u251c\u2500\u2500 jenkins\/\n\u2502   \u2514\u2500\u2500 Jenkinsfile         # Jenkins CI\/CD pipeline script\n\u2502\n\u251c\u2500\u2500 Dockerfile              # Docker image for MedusaJS backend\n\u251c\u2500\u2500 docker-compose.yml      # Local development setup\n\u2514\u2500\u2500 README.md               # This file\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\ude80 Features<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-features\"><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CI\/CD pipeline triggered via Jenkins<\/li>\n\n\n\n<li>Deployment on AKS using kubectl<\/li>\n\n\n\n<li>External LoadBalancer to access Medusa Admin UI<\/li>\n\n\n\n<li>Logs and service monitoring with&nbsp;<code>kubectl<\/code><\/li>\n\n\n\n<li>Secure PostgreSQL with volume persistence<\/li>\n\n\n\n<li>Easily scalable &amp; production-ready<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udee0\ufe0f Setup &amp; Deployment<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#%EF%B8%8F-setup--deployment\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Clone the Repo<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#1-clone-the-repo\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git clone <a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2.git\">https:\/\/github.com\/jaspreet237\/MedusajsV2.git<\/a><br>cd MedusajsV2<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Build Docker Images<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#2-build-docker-images\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker build -t medusa-app .\ndocker-compose up -d<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Push to Docker Hub<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#3-push-to-docker-hub\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker tag medusa-app &lt;your-dockerhub-username&gt;\/medusa-app\ndocker push &lt;your-dockerhub-username&gt;\/medusa-app<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Create AKS Cluster (Optional: if not already created)<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#4-create-aks-cluster-optional-if-not-already-created\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">az aks create --resource-group rg-aks-dev --name my-aks-cluster --node-count 1 --generate-ssh-keys\naz aks get-credentials --resource-group rg-aks-dev --name my-aks-cluster<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. Apply Kubernetes Manifests<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#5-apply-kubernetes-manifests\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubectl apply -f k8s\/postgres.yaml\nkubectl apply -f k8s\/deployment.yaml\nkubectl apply -f k8s\/service.yaml<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. Access Application<\/h3>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#6-access-application\"><\/a><\/p>\n\n\n\n<p>Check external IP:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubectl get svc medusa-service<\/pre>\n\n\n\n<p>Visit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;&lt;EXTERNAL-IP&gt;:9000\/app\/login\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddea Create Admin User (Inside Pod)<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-create-admin-user-inside-pod\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubectl exec -it &lt;medusa-pod-name&gt; -- yarn medusa user -e admin@mail.com -p password<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddf0 Jenkins CI\/CD Setup<a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-jenkins-cicd-setup\"><\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pipeline includes steps to:\n<ul class=\"wp-block-list\">\n<li>Clone repo<\/li>\n\n\n\n<li>Build Docker image<\/li>\n\n\n\n<li>Push to Docker Hub<\/li>\n\n\n\n<li>Apply Kubernetes manifests<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Example Jenkinsfile is included under\u00a0<code>jenkins\/<\/code>.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcb0 Azure AKS Cost Estimation (For MedusaJS V2 Deployment)<\/h2>\n\n\n\n<p>Deploying MedusaJS v2 on <strong>Azure Kubernetes Service (AKS)<\/strong> 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2699\ufe0f Resource Breakdown (1-Node Setup)<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Component<\/th><th>Resource Type<\/th><th>Estimated Monthly Cost (INR\/USD)<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><strong>AKS Cluster Node<\/strong><\/td><td>Standard_B2s (2 vCPU, 4 GB RAM)<\/td><td>\u20b92,000 \/ $25<\/td><td>Runs MedusaJS and PostgreSQL pods<\/td><\/tr><tr><td><strong>AKS Control Plane<\/strong><\/td><td>Managed by Azure<\/td><td>Free<\/td><td>Control plane is free for 1st cluster<\/td><\/tr><tr><td><strong>Azure Container Registry (Optional)<\/strong><\/td><td>Basic Tier<\/td><td>\u20b9350 \/ $5<\/td><td>Stores Docker images for deployment<\/td><\/tr><tr><td><strong>Managed Disk (Persistent Storage)<\/strong><\/td><td>20 GB Premium SSD<\/td><td>\u20b9300 \/ $4<\/td><td>Persistent volume for PostgreSQL<\/td><\/tr><tr><td><strong>Azure Load Balancer<\/strong><\/td><td>Standard SKU<\/td><td>\u20b9700 \/ $9<\/td><td>Provides external access to MedusaJS API<\/td><\/tr><tr><td><strong>Public IP (Static)<\/strong><\/td><td>1 Static IP<\/td><td>\u20b9250 \/ $3<\/td><td>Assigned to the LoadBalancer service<\/td><\/tr><tr><td><strong>Bandwidth \/ Egress Data<\/strong><\/td><td>~50 GB outbound\/month<\/td><td>\u20b9500 \/ $6<\/td><td>Depends on app traffic and usage<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\ud83d\udfe9 Estimated Monthly Total:<\/strong> ~ \u20b94,100 \u2013 \u20b95,000 (~$50 \u2013 $60 USD)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\ud83d\udca1 <em>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.<\/em><\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcc8 Scaling Cost for Additional Applications or Pods<\/h3>\n\n\n\n<p>If you want to deploy <strong>multiple MedusaJS backends or microservices<\/strong>, the cost scales linearly based on pod and node utilization.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Scenario<\/th><th>Example<\/th><th>Approx. Cost Impact<\/th><\/tr><\/thead><tbody><tr><td><strong>2 MedusaJS Apps<\/strong><\/td><td>2 Deployments sharing same AKS Node<\/td><td>+\u20b91,000 \/ +$12<\/td><\/tr><tr><td><strong>3\u20134 MedusaJS Apps<\/strong><\/td><td>Requires 2nd AKS Node<\/td><td>+\u20b92,000 \/ +$25<\/td><\/tr><tr><td><strong>Horizontal Pod Autoscaler<\/strong><\/td><td>Scales automatically with load<\/td><td>Based on CPU usage and node addition<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\ud83d\udd39 Each new node adds approximately <strong>\u20b92,000\u2013\u20b92,500 ($25\u2013$30)<\/strong> per month.<br>\ud83d\udd39 Storage and bandwidth usage also increase proportionally.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83e\uddee How to Estimate Exact Cost<\/h3>\n\n\n\n<p>You can calculate your precise AKS expenses using the <strong>Azure Pricing Calculator<\/strong>:<\/p>\n\n\n\n<p>\ud83d\udd17 <a href=\"https:\/\/azure.microsoft.com\/en-us\/pricing\/calculator\">https:\/\/azure.microsoft.com\/en-us\/pricing\/calculator<\/a><\/p>\n\n\n\n<p>To use it:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Add <strong>Azure Kubernetes Service<\/strong><\/li>\n\n\n\n<li>Select <strong>VM Size<\/strong> (e.g., B2s or D2s_v3) and region<\/li>\n\n\n\n<li>Include <strong>Storage<\/strong>, <strong>Bandwidth<\/strong>, and <strong>Public IP<\/strong><\/li>\n\n\n\n<li>Compare between <strong>Dev\/Test<\/strong> and <strong>Production<\/strong> usage levels<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83e\ude84 Cost Optimization Tips<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <strong>B-series VMs<\/strong> for development (low-cost burstable instances)<\/li>\n\n\n\n<li>Enable <strong>node auto-scaling<\/strong> to reduce idle costs<\/li>\n\n\n\n<li>Schedule <strong>cluster shutdown<\/strong> for non-production workloads<\/li>\n\n\n\n<li>Store Docker images in <strong>Azure Container Registry (Basic tier)<\/strong><\/li>\n\n\n\n<li>Monitor and right-size resources using <strong>Azure Advisor<\/strong><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc Future Enhancements<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-future-enhancements\"><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Implement Ingress Controller (Nginx or Traefik)<\/li>\n\n\n\n<li>Enable TLS with Let&#8217;s Encrypt<\/li>\n\n\n\n<li>Add Redis for caching &amp; job queue<\/li>\n\n\n\n<li>Configure Horizontal Pod Autoscaler<\/li>\n\n\n\n<li>Enable Role-Based Access Control (RBAC)<\/li>\n\n\n\n<li>Integrate monitoring (Prometheus + Grafana)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 What You Can Learn From This Project<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-what-you-can-learn-from-this-project\"><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Real-world AKS deployment<\/li>\n\n\n\n<li>End-to-end DevOps pipeline using Jenkins<\/li>\n\n\n\n<li>Secure and scalable Kubernetes practices<\/li>\n\n\n\n<li>Practical MedusaJS backend usage<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udd1d Contributing<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/jaspreet237\/MedusajsV2#-contributing\"><\/a><\/p>\n\n\n\n<p>Pull requests and stars are welcome! For major changes, please open an issue first.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This project demonstrates a production-like deployment of a&nbsp;MedusaJS v2 ecommerce backend&nbsp;using&nbsp;Docker,&nbsp;Jenkins CI\/CD,&nbsp;Azure Kubernetes Service (AKS), and&nbsp;PostgreSQL. The backend exposes REST APIs and an admin panel for managing ecommerce operations. \ud83d\udd27 Tech Stack \ud83d\udcc1 Project Structure \ud83d\ude80 Features \ud83d\udee0\ufe0f Setup &amp; Deployment 1. Clone the Repo git clone https:\/\/github.com\/jaspreet237\/MedusajsV2.gitcd MedusajsV2 2. Build Docker Images docker build\u2026 <span class=\"read-more\"><a href=\"https:\/\/myallcodes.in\/index.php\/2025\/07\/25\/deployment-of-medusajs-v2-ecommerce-backend-on-aks-azure-kubernetes-service\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-power-shell-scripts"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/comments?post=268"}],"version-history":[{"count":2,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/posts\/268\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myallcodes.in\/index.php\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}