This repository contains a demo project created as part of my DevOps studies in the TechWorld with Nana – DevOps Bootcamp.
https://www.techworld-with-nana.com/devops-bootcamp
Demo Project: Deploy MongoDB and Mongo Express into local K8s cluster
Technologies used: Kubernetes, Docker, MongoDB, Mongo Express
Project Description:
- Setup local K8s cluster with Minikube
- Deploy MongoDB and MongoExpress with configuration and credentials extracted into ConfigMap and Secret
Install Minikube by following the official documentation.
The setup consists of a MongoDB database and a Mongo Express web UI, with credentials stored in a Kubernetes Secret and the database URL stored in a ConfigMap.
kubectl create deploy mongodb-deployment --image mongo --dry-run=client -o yaml > mongo.yamlSee: mongo.yaml
Base64-encode the credentials:
echo -n 'root-user' | base64
# cm9vdC11c2Vy
echo -n 'root-password' | base64
# cm9vdC1wYXNzd29yZA==See: mongo-secret.yaml
Apply the secret:
kubectl apply -f mongo-secret.yamlAdd the following environment variables to the container spec in mongo.yaml:
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-passwordSee: mongo.yaml
kubectl apply -f mongo.yamlAppend the following Service definition to mongo.yaml:
---
apiVersion: v1
kind: Service
metadata:
name: mongodb-service
spec:
selector:
app: mongodb-deployment
ports:
- protocol: TCP
port: 27017
targetPort: 27017See: mongo.yaml
Apply the updated manifest:
kubectl apply -f mongo.yamlkubectl create configmap mongodb-configmap \
--from-literal=database_url="mongodb-service:27017" \
--dry-run=client -o yaml > mongo-configmap.yamlApply the ConfigMap:
kubectl apply -f mongo-configmap.yamlGenerate the base manifest:
kubectl create deploy mongo-express --image mongo-express --dry-run=client -o yaml > mongo-express.yamlThen add the following environment variables to the container spec:
env:
- name: ME_CONFIG_MONGODB_ADMINUSERNAME
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-username
- name: ME_CONFIG_MONGODB_ADMINPASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-password
- name: DATABASE_URL
valueFrom:
configMapKeyRef:
name: mongodb-configmap
key: database_url
- name: ME_CONFIG_MONGODB_URL
value: "mongodb://$(ME_CONFIG_MONGODB_ADMINUSERNAME):$(ME_CONFIG_MONGODB_ADMINPASSWORD)@$(DATABASE_URL)"See: mongo-express.yaml
Deploy Mongo Express:
kubectl apply -f mongo-express.yamlAppend the following Service definition to mongo-express.yaml:
---
apiVersion: v1
kind: Service
metadata:
name: mongo-express-service
spec:
selector:
app: mongo-express
type: LoadBalancer
ports:
- protocol: TCP
port: 8081
targetPort: 8081
nodePort: 30000See: mongo-express.yaml
Apply the updated manifest:
kubectl apply -f mongo-express.yamlExpose the service via Minikube:
minikube service mongo-express-serviceSign in with the default Mongo Express credentials:
| Field | Value |
|---|---|
| Username | admin |
| Password | pass |







