MongoDB + Mongo Express on Kubernetes
This repository contains Kubernetes manifests to deploy a MongoDB StatefulSet with persistent storage and a Mongo Express web interface for managing your database. It includes initial data seeding and secure credentials using Kubernetes Secrets.
-
MongoDB StatefulSet with persistent storage (1Gi)
-
Headless service for MongoDB for stable pod networking
-
Mongo Express Deployment with ClusterIP service
-
ConfigMap for initializing
product-service-dbwith sampleproducts -
Kubernetes Secrets for secure credentials
After deployment, open your browser at, and you should see the Mongo Express deployment http://localhost:8081
i. Kubernetes cluster (kind)
ii. kubectl installed and configured
- Optional:
helmif you want to use charts later
kubectl apply -f mongo-secret.yamlThis will create the MongoDB root credentials and Mongo Express login credentials.
kubectl apply -f configmap.yaml
The ConfigMap seeds the MongoDB database with sample products.
kubectl apply -f mongo-db.yaml
- The StatefulSet creates a persistent volume claim for data storage.
- MongoDB runs on port 27017 and uses the headless service mongo-headless
kubectl apply -f mongo-express.yaml
- Mongo Express runs on port 8081.
- Connects to MongoDB using the headless service mongo-headless.
local cluster
kubectl port-forward svc/mongo-express-service 8081:8081
kubectl delete -f mongo-express.yaml
kubectl delete -f mongo-db.yaml
kubectl delete -f configmap.yaml
kubectl delete -f mongo-secret.yaml