Back to projects
This project demonstrates how to deploy a highly available MongoDB replica set with a web UI using Mongo Express, running on a managed Kubernetes cluster in Linode Kubernetes Engine (LKE). Traffic from the browser is routed through Nginx Ingress to the Mongo Express UI.
The first step was to create the Kubernetes cluster itself. Linode makes this really easy with LKE:
Once the cluster was ready, Linode gave me a mdb-cluster-kubeconfig.yaml file to connect locally.
Next, I wanted a replicated MongoDB cluster, with 1 primary, 2 secondaries, and an arbiter. I went with Helm for simplicity:
Then I ran:
helm install mongodb --values helm-mongodb.yaml bitnami/mongodb
which created the underlying persistent volumes for my 3 mongodb pods, aswell as the pods themselves, and all other necessary k8s ressources.
Here’s what was created under the hood:
The primary pod handles all write requests, and the secondaries replicate data asynchronously. The arbiter participates in leader elections but doesn’t store any data.
With MongoDB running, I wanted a way to visualize and manage the database. That’s where Mongo Express comes in.
I created a Deployment with a single pod and a ClusterIP service (didn't use Helm charts here cuz I didn't feel the need to as this is just a simple 1 replica pod mongo-express):
A few things to note:
Logs after applying the mongo-express deployment:
Finally, I wanted to make the UI accessible externally without exposing the pod directly. That’s where Nginx Ingress comes in.
Install the ingress controller:
This deployed an Nginx pod that listens for incoming HTTP requests and Linode automatically created a public IP load balancer for the ingress controller, so it can accept internet traffic.
Create an Ingress resource:
How traffic flows now:
Now our mongo-express can be accessed through the web using the dns generated for the public ip address of our Linode load balancer:
