Skip to content

Eldemerdash2/deploying-mongodb-and-mongo-express-in-Kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧩 DevOps Project: Deploying MongoDB & Mongo Express in Kubernetes

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.


📋 Project Overview

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 (.yaml files)
  • Configure environment variables securely
  • Manage internal and external connectivity between services
  • Access applications from a browser

🏗️ Architecture Diagram

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) ]

⚙️ Components

1. MongoDB Deployment

  • Creates a MongoDB Pod running the latest official mongo image.
  • Exposes port 27017.
  • Credentials (username/password) are not hardcoded but referenced from a Kubernetes Secret.

2. MongoDB Service (Internal)

  • Type: ClusterIP
  • Makes MongoDB accessible only within the cluster.
  • Connects to Mongo Express through the service name.

3. Secret (mongodb-secret)

Stores MongoDB credentials securely.

4. ConfigMap (mongodb-configmap)

Contains the MongoDB service endpoint for Mongo Express to connect to.

5. Mongo Express Deployment

  • Uses the mongo-express image.
  • Exposes port 8081.
  • Reads database URL from ConfigMap and credentials from Secret.

6. Mongo Express Service (External)

  • Type: LoadBalancer
  • Opens NodePort 30000, allowing browser access.
  • Maps port 8081 (container) → 30000 (external).

🧠 Request Flow

  1. User sends HTTP request → NodeIP:30000
  2. LoadBalancer service (mongo-express-service) forwards request to Mongo Express Pod
  3. Mongo Express connects to internal service (mongodb-service)
  4. Internal service routes request to MongoDB Pod
  5. MongoDB authenticates using credentials from Secret

🧰 Prerequisites


🚀 Deployment Steps

  1. Start your Kubernetes cluster
    minikube start --driver docker
image
  1. Create the Secret
    kubectl apply -f mongo-secret.yaml
image
  1. Create the ConfigMap

    kubectl apply -f mongo-configmap.yaml
    image
  2. Deploy MongoDB

    kubectl apply -f mongo.yaml
    image
  3. Deploy Mongo Express

    kubectl apply -f mongo-express.yaml
    image
  4. Check all resources

    kubectl get all
image
  1. Access the application through Tunnel
    minikube service mongo-express-service
image

This will open Mongo Express in your default browser.

image ---

🔍 Validation

To verify the setup:

kubectl logs mongo-express-68c7cbfbfd-zjv2z
kubectl describe service mongodb-service

🧹 Cleanup

To remove all components:

kubectl delete -f .

📊 Summary

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

🖼️ Visual Overview

0693846b-7644-4c35-95a2-bfbf9a6242d5

🧑‍💻 Author

Mohamed Eldemerdash
DevOps Engineer & Mechanical Engineer

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published