A simplified 3-tier application built with MongoDB, Express, React (HTML/JS), and Node.js for demonstration purposes.
This is a basic Pet Shelter application that allows users to:
The application consists of:
Frontend (Port 3000) --> Backend API (Port 5100:5000) --> MongoDB (Port 27017)
GET /api/pets - Retrieve all petsPOST /api/pets - Add a new petBackend runs on port 5000 inside Docker, mapped to port 5100 on host (Mac uses port 5000 for AirPlay).
Build and run all services:
docker-compose up --build
Access the application at http://localhost:3000
Build and tag images:
# Backend
cd backend
docker build -t dimilan/pet-shelter-backend:latest .
docker push dimilan/pet-shelter-backend:latest
# Frontend
cd ../frontend
docker build -t dimilan/pet-shelter-frontend:latest .
docker push dimilan/pet-shelter-frontend:latest
minikube start
eval $(minikube docker-env)
cd backend docker build -t dimilan/pet-shelter-backend:latest .
cd ../frontend docker build -t dimilan/pet-shelter-frontend:latest .
cd ..
3. Apply Kubernetes configurations:
```bash
kubectl apply -f k8s/mongodb-secret.yaml
kubectl apply -f k8s/mongodb-configmap.yaml
kubectl apply -f k8s/mongodb-deployment.yaml
kubectl apply -f k8s/backend-deployment.yaml
kubectl apply -f k8s/frontend-deployment.yaml
kubectl get pods -w
minikube service frontend-service
minikube ip
6. Verify the application:
```bash
# Check backend logs for database seeding
kubectl logs -l app=backend
# Should show:
# Connecting to MongoDB...
# Server running on port 5000
# Connected to MongoDB
# Database seeded with initial pets
Note: Images use imagePullPolicy: Never to use locally built images in Minikube instead of pulling from DockerHub.
username: admin (base64: YWRtaW4=)password: password (base64: cGFzc3dvcmQ=)database-url: mongodb-servicedatabase-port: 27017database-name: petshelterThe backend constructs the MongoDB connection string from individual environment variables sourced from the Secret and ConfigMap, following security best practices.
MONGO_URL: MongoDB connection string (from ConfigMap in K8s)PORT: Server port (default: 5000)MONGO_INITDB_ROOT_USERNAME: Admin username (from Secret in K8s)MONGO_INITDB_ROOT_PASSWORD: Admin password (from Secret in K8s)