A simple web application with MongoDB backend deployed on Kubernetes using Minikube.
- Minikube installed
- kubectl installed
- Docker installed (for Minikube)
- Web Application: Node.js app running on port 3000
- MongoDB: Database backend
- ConfigMap: Stores MongoDB connection URL
- Secret: Stores MongoDB credentials
# Start Minikube cluster
minikube start
# Verify Minikube is running
minikube status
# Get Minikube IP (needed to access the app)
minikube ipDeploy components in the following order:
# 1. Create the Secret (MongoDB credentials)
kubectl apply -f mongo-secret.yaml
# 2. Create the ConfigMap (MongoDB URL)
kubectl apply -f mongo-config.yaml
# 3. Deploy MongoDB and its Service
kubectl apply -f mongo.yaml
# 4. Deploy Web Application and its Service
kubectl apply -f webapp.yaml# Check all pods are running
kubectl get pods
# Check all services
kubectl get services
# Get detailed information about pods
kubectl describe pods
# Check deployments
kubectl get deployments
# View logs of a specific pod
kubectl logs <pod-name>
# Example: View webapp logs
kubectl logs -l app=webappThe web application is exposed via NodePort service on port 30100.
# Get the Minikube IP
minikube ip
# Access the application in your browser
# URL: http://<minikube-ip>:30100
# Example: http://192.168.49.2:30100Alternatively, use Minikube service command:
# This will open the webapp in your default browser
minikube service webapp-service# Watch pods in real-time
kubectl get pods -w
# Get pod events
kubectl get events --sort-by='.lastTimestamp'
# Execute commands inside a pod
kubectl exec -it <pod-name> -- /bin/bash
# Check service endpoints
kubectl get endpoints
# Describe a service
kubectl describe service webapp-serviceIf you make changes to the YAML files:
# Apply changes
kubectl apply -f <yaml-file>
# Force restart a deployment
kubectl rollout restart deployment webapp-deployment
kubectl rollout restart deployment mongo-deployment
# Check rollout status
kubectl rollout status deployment webapp-deployment# Delete all resources
kubectl delete -f webapp.yaml
kubectl delete -f mongo.yaml
kubectl delete -f mongo-config.yaml
kubectl delete -f mongo-secret.yaml
# Or delete everything at once
kubectl delete -f .
# Stop Minikube
minikube stop
# Delete Minikube cluster (removes all data)
minikube delete-
Verify the service selector matches pod labels:
kubectl get pods --show-labels kubectl get service webapp-service -o yaml
-
Check if pods are running:
kubectl get pods
-
Check service endpoints:
kubectl get endpoints webapp-service
-
Test connectivity from within the cluster:
kubectl run test-pod --image=busybox -it --rm -- wget -O- webapp-service:3000
# Check pod logs
kubectl logs <pod-name>
# Check previous pod logs (if pod restarted)
kubectl logs <pod-name> --previous
# Describe pod for events and status
kubectl describe pod <pod-name># Open Kubernetes dashboard
minikube dashboard.
├── README.md # This file
├── mongo-secret.yaml # MongoDB credentials (base64 encoded)
├── mongo-config.yaml # MongoDB service URL configuration
├── mongo.yaml # MongoDB deployment and service
└── webapp.yaml # Web application deployment and service
- The web application is accessible on NodePort 30100
- MongoDB runs internally on port 27017
- Make sure the Minikube VM has enough resources (CPU/Memory)
- Default credentials are stored in mongo-secret.yaml (base64 encoded)