This project demonstrates how to deploy a web application (Mongo Express) and a database (MongoDB) on a Kubernetes cluster, using best DevOps practices such as ConfigMaps, Secrets, Deployments, and Services.
This setup showcases a classic two-tier application structure:
- MongoDB → backend database
- Mongo Express → web-based admin interface for MongoDB
🚀 Highlight:
- Deploy applications using Kubernetes manifests (
.yamlfiles) - Configure environment variables securely
- Manage internal and external connectivity between services
- Access applications from a browser
Below is a visual representation of the project workflow:
Browser (HTTP Request: NodeIP:30000)
|
v
[ External Service (LoadBalancer): mongo-express-service ]
|
v
[ Mongo Express Pod (Deployment) ]
|---> Reads DB URL from ConfigMap
|---> Reads Credentials from Secret
|
v
[ Internal Service (ClusterIP): mongodb-service ]
|
v
[ MongoDB Pod (Deployment) ]
- Creates a MongoDB Pod running the latest official
mongoimage. - Exposes port 27017.
- Credentials (username/password) are not hardcoded but referenced from a Kubernetes Secret.
- Type:
ClusterIP - Makes MongoDB accessible only within the cluster.
- Connects to Mongo Express through the service name.
Stores MongoDB credentials securely.
Contains the MongoDB service endpoint for Mongo Express to connect to.
- Uses the
mongo-expressimage. - Exposes port 8081.
- Reads database URL from ConfigMap and credentials from Secret.
- Type:
LoadBalancer - Opens NodePort 30000, allowing browser access.
- Maps port
8081(container) →30000(external).
- User sends HTTP request →
NodeIP:30000 - LoadBalancer service (
mongo-express-service) forwards request to Mongo Express Pod - Mongo Express connects to internal service (
mongodb-service) - Internal service routes request to MongoDB Pod
- MongoDB authenticates using credentials from Secret
- Minikube
- kubectl
- Docker
- Visual Studio Code (optional for editing YAML files)
- Start your Kubernetes cluster
minikube start --driver docker
- Create the Secret
kubectl apply -f mongo-secret.yaml
-
Create the ConfigMap
kubectl apply -f mongo-configmap.yaml
-
Deploy MongoDB
kubectl apply -f mongo.yaml
-
Deploy Mongo Express
kubectl apply -f mongo-express.yaml
-
Check all resources
kubectl get all
- Access the application through Tunnel
minikube service mongo-express-service
This will open Mongo Express in your default browser.
---
To verify the setup:
kubectl logs mongo-express-68c7cbfbfd-zjv2z
kubectl describe service mongodb-serviceTo remove all components:
kubectl delete -f .| Component | Type | Purpose |
|---|---|---|
| MongoDB Deployment | Pod | Database backend |
| MongoDB Service | ClusterIP | Internal DB access |
| Mongo Express Deployment | Pod | Web admin for MongoDB |
| Mongo Express Service | LoadBalancer | External access |
| ConfigMap | Key-Value Store | Stores MongoDB URL |
| Secret | Encrypted Data | Stores credentials |
Mohamed Eldemerdash
DevOps Engineer & Mechanical Engineer