Skip to content

explicit-logic/kubernetes-module-10.3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module 10 - Container Orchestration with Kubernetes

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: Install a stateful service (MongoDB) on Kubernetes using Helm

Technologies used: K8s, Helm, MongoDB, Mongo Express, DigitalOcean Kubernetes, Linux

Project Description:

  • Create a managed K8s cluster with DigitalOcean Kubernetes
  • Deploy replicated MongoDB service in DOKS cluster using a Helm chart
  • Configure data persistence for MongoDB with DigitalOcean block storage
  • Deploy UI client Mongo Express for MongoDB
  • Deploy and configure nginx ingress to access the UI application from browser

1. Create a Kubernetes Cluster on DigitalOcean

Provision a managed Kubernetes cluster through the DigitalOcean dashboard:

Cluster Configuration

2. Connect to the Cluster

Download the kubeconfig file from DigitalOcean, then configure access:

chmod 400 k8s-id-kubeconfig.yaml
export KUBECONFIG=k8s-id-kubeconfig.yaml

Verify the connection:

kubectl cluster-info
kubectl get nodes

Cluster Connection

3. Install Helm

Install the Helm package manager by following the official installation guide.

4. Add the Bitnami Helm Repository

helm repo add bitnami https://charts.bitnami.com/bitnami

5. Configure MongoDB

Search for the available MongoDB chart versions:

helm search repo bitnami/mongodb

For detailed chart parameters, see the Bitnami MongoDB chart documentation.

Check the available storage classes in your cluster:

kubectl get storageclass

Set the appropriate storage class in helm-mongodb.yaml:

persistence:
  storageClass: "do-block-storage"

6. Deploy MongoDB

helm install mongodb --values helm-mongodb.yaml bitnami/mongodb

MongoDB Deployment

A PersistentVolumeClaim (PVC) is automatically created for each of the 3 replica pods:

PVCs

7. Deploy Mongo Express (MongoDB UI Client)

Retrieve the MongoDB secret configuration:

kubectl get secret mongodb -o yaml

The Mongo Express deployment uses the following environment variables to connect to MongoDB (see helm-mongo-express.yaml):

env:
  - name: ME_CONFIG_MONGODB_ADMINUSERNAME
    value: root
  - name: ME_CONFIG_MONGODB_ADMINPASSWORD
    valueFrom:
      secretKeyRef:
        name: mongodb
        key: mongodb-root-password
  - name: ME_CONFIG_MONGODB_URL
    value: "mongodb://$(ME_CONFIG_MONGODB_ADMINUSERNAME):$(ME_CONFIG_MONGODB_ADMINPASSWORD)@mongodb-0.mongodb-headless:27017"

Note: mongodb-0.mongodb-headless refers to the first pod in the StatefulSet, resolved via the headless service (verify with kubectl get svc).

Apply the deployment:

kubectl apply -f helm-mongo-express.yaml

Verify the pod is running:

kubectl get pod

Mongo Express Logs

8. Deploy and Configure Nginx Ingress Controller

Add the ingress-nginx Helm repository:

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

Install the Nginx Ingress Controller:

helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.publishService.enabled=true

Verify the controller is running:

kubectl get pods
kubectl logs nginx-ingress-ingress-nginx-controller-<pod-id>

Nginx Ingress Logs

A DigitalOcean Load Balancer is automatically provisioned:

Load Balancers

Note the external IP address assigned to the ingress service:

kubectl get svc

Nginx Ingress Service

9. Create and Apply the Ingress Rule

Update the host in helm-ingress.yaml with your external IP (replacing dots with dashes):

- host: <your-ip-address>.nip.io
  # Replace <your-ip-address> with your actual external IP

Apply the ingress rule:

kubectl apply -f helm-ingress.yaml

Ingress Rule

10. Access the Application

Navigate to http://<your-ip-address>.nip.io in your browser.

Default credentials:

Field Value
User admin
Password pass

Demo

About

Install a stateful service (MongoDB) on Kubernetes using Helm

Topics

Resources

Stars

Watchers

Forks

Contributors