The diagram below provides a visual representation of the services used in this setup to deploy the EasyShop application. This project is hosted on a local Virtual machine, which serves as the base infrastructure. We utilize Docker to build application images and to run Kind (Kubernetes in Docker), which creates a lightweight Kubernetes cluster within the Local VM.
The application images are stored in Docker Hub. Within the Kind cluster, external traffic is managed by the NGINX Ingress Controller, which routes requests to the EasyShop application pods. The application then connects to a MongoDB StatefulSet for data persistence.
What Do We Need?
- Local VM (Ubuntu x64): A virtual machine running Ubuntu x64 acts as the primary infrastructure. It serves as the host for deploying the cluster and running all necessary Docker commands.
- Git & GitHub: Git is used for version control to manage the codebase locally, while GitHub serves as the remote repository to host the source code of the EasyShop application.
- Docker: Used to containerize the application by building Docker Images from the Dockerfile. It is also required to run the Kind nodes, which operate as Docker containers.
- Docker Hub: The container registry used to store and share the built images (Application and Migration images), making them accessible to the cluster.
- Kind (Kubernetes in Docker): A tool for running local Kubernetes clusters using Docker container "nodes". It simulates the production environment inside your local VM.
Prerequisites Installation:
Linux:
Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
rm get-docker.sh
Install Kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.27.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
Environment Setup
- Clone the repository and navigate to the project directory
git clone https://github.com/YadneshR/Easy_Shop_Containerization_and_Orchestration.git
cd EasyShop
- Build and Push Docker Images
First, login to Docker Hub (create an account at hub.docker.com if you haven't :
docker login
Build Application Image
# Build the application image
docker build -t your-dockerhub-username/easyshop:latest .
# Push to Docker Hub
docker push your-dockerhub-username/easyshop:latest
Build Migration Image
# Build the migration image
docker build -t your-dockerhub-username/easyshop-migration:latest -f Dockerfile.migration /scripts .
# Push to Docker Hub
docker push your-dockerhub-username/easyshop-migration:latest
Kind Cluster Setup
Create new cluster
kind create cluster --name easyshop --config kubernetes/00-kind-config.yaml
This command creates a new Kind cluster using our custom configuration with one control plane.
Create namespace
kubectl apply -f kubernetes/01-namespace.yaml
Setup storage
kubectl apply -f kubernetes/02-mongodb-pv.yaml
kubectl apply -f kubernetes/03-mongodb-pvc.yaml
Create ConfigMap
Create kubernetes/04-configmap.yaml with the following content:
apiVersion: v1
kind: ConfigMap
metadata:
name: easyshop-config
namespace: easyshop
data:
MONGODB_URI: "mongodb://mongodb-service:27017/easyshop"
NODE_ENV: "production"
NEXT_PUBLIC_API_URL: "http://easyshop.local/api" # Add custom local domain or EC2 ip
NEXTAUTH_URL: "http://easyshop.local" # Add custom local domain or EC2 ip
NEXTAUTH_SECRET: "Generate your own NEXTAUTH secret"
JWT_SECRET: "Generate your own JWT secret"
ADD CUSTOM DOMAIN IF ON LOCAL VM
vim /etc/hosts
Add this line at the bottom in the file
127.0.0.1 easyshop.local
ping easyshop.local
To generate secure secret keys, use these commands in your terminal:
# For NEXTAUTH_SECRET
openssl rand -base64 32
# For JWT_SECRET
openssl rand -hex 32
After making changes in configmap.yml
kubectl apply -f kubernetes/04-configmap.yaml
Setup configuration
kubectl apply -f kubernetes/05-secrets.yaml
Deploy MongoDB
kubectl apply -f kubernetes/06-mongodb-service.yaml
kubectl apply -f kubernetes/07-mongodb-statefulset.yaml
Deploy EasyShop
Make necessary changes such as:
- Change image name
kubectl apply -f kubernetes/08-easyshop-deployment.yaml
kubectl apply -f kubernetes/09-easyshop-service.yaml
Install NGINX Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
Deploy Ingress and HPA
Make necessary changes such as:
- Change the host to
http://easyshop.local
kubectl apply -f kubernetes/10-ingress.yaml
kubectl apply -f kubernetes/11-hpa.yaml
Update Migration Job with your docker image :
apiVersion: batch/v1
kind: Job
metadata:
name: db-migration
namespace: easyshop
spec:
template:
spec:
containers:
- name: migration
image: your_username/easyshop-migration:latest # update with the name that you have build.
imagePullPolicy: Always
env:
- name: MONGODB_URI
value: "mongodb://mongodb-service:27017/easyshop"
restartPolicy: OnFailure
# Run database migration
kubectl apply -f kubernetes/migration-job.yaml

Verify it on your machine browser
http://easyshop.local











Top comments (0)