Kubernetes MERN Lab

Full-Stack Deployment Guide
Step 1: Setup

Clone the Repository

01:25:58

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.
Step 2: Isolation

Create Namespace

01:04:02

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.
Step 3: Deploy

Apply Manifests

01:28:19

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.
Troubleshooting

Fixing Pending Pods

01:31:18

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.
Step 4: Scaling

Scale Replicas

01:47:37

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.
Step 5: Healing

POD Healing

01:55:35

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.
Step 6: Updates

Rolling Updates & Rollbacks

02:00:14

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.
Step 7: Networking

Services & NodePort

02:22:33

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.