Kubernetes MERN Lab
Full-Stack Deployment Guide
Clone the Repository
Start by configuring your environment and cloning the lab repository.
Terminal
git clone https://github.com/sasidatta/docker_demo.git
cd docker_demo/k8s
git clone downloads the code repository to your machine. cd changes
the directory to the folder containing Kubernetes files.
Create Namespace
Create a dedicated namespace for your resources.
Terminal
kubectl create namespace sasi-lab
kubectl create namespace creates a virtual cluster partition named
sasi-lab to keep your resources organized and isolated.
Apply Manifests
Deploy the Frontend, Backend, and MongoDB. We will use the specific latest images:
- Frontend:
sasidatta/mern-docker-frontend:1b62387659cc28b0c284a2fbf95f5f8c17bd68fdfe5b2b4cdbe46c51f4785ed2 - Backend:
sasidatta/mern-docker-backend:ca8b74511d7d6ce5e22ccf01418b20b167acb739
Terminal
kubectl apply -f . -n sasi-lab
kubectl apply -f . tells Kubernetes to create all resources defined in YAML files
in the current folder. -n sasi-lab specifies the target namespace.
Fixing Pending Pods
If pods are stuck in Pending (common on ARM64/Apple Silicon nodes), remove the
nodeSelector constraint.
kubectl edit deployment backend -n
sasi-lab
# Remove 'nodeSelector: arch: amd64'
kubectl edit opens the current live configuration in your default text editor (like
vi). Saving changes will update the resource immediately.
Scale Replicas
Increase the number of backend replicas to handle more load.
Terminal
kubectl scale deployment backend --replicas=3 -n sasi-lab
kubectl get pods -n sasi-lab
kubectl scale updates the number of running instances (pods).
kubectl get pods lists all pods, letting you verify 3 are running.
POD Healing
Kubernetes ensures the desired state. If we delete a pod, the Deployment controller will immediately recreate it.
Terminal
# 1. List pods to find a name
kubectl get pods -n sasi-lab -l app=frontend
# 2. Delete one frontend pod (replace name below)
kubectl delete pod frontend-YOUR-POD-ID -n sasi-lab
# 3. Watch it come back immediately
kubectl get pods -n sasi-lab -w
# 4. Exercise: Delete ALL frontend pods!
kubectl delete pods -l app=frontend -n sasi-lab
# 5. Watch mass self-healing
kubectl get pods -n sasi-lab -w
kubectl delete permanently removes a resource. -l app=frontend selects
all pods matching that label. -w watches for changes in real-time.
Rolling Updates & Rollbacks
To simulate a rolling update, we will switch the frontend image to a different version tag:
5bcc1d...
Terminal
# Update image to a specific tag
kubectl set image deployment/frontend
frontend=sasidatta/mern-docker-frontend:5bcc1d2968da5af161d3e975e211c2749acb9145 -n sasi-lab
# Check status
kubectl rollout status deployment/frontend -n sasi-lab
# Undo breakdown
kubectl rollout undo deployment/frontend -n sasi-lab
kubectl set image updates the valid image for a deployment.
rollout status tracks progress. rollout undo reverts to the previous
version.
Services & NodePort
Expose your application using a NodePort to access it externally.
Terminal
kubectl get svc -n sasi-lab
kubectl get svc lists all Services (internal load balancers). Look for ports like
3000:3xxxx to find your external access port.