Über Xelon
image image

Welcome to Xelon Knowledge Base

<learn> use </share>

image image

How to: Deploy MongoDB on Kubernetes Cluster


This article provides a step-by-step procedure on how to deploy a MongoDB using Kubernetes. To show this example we use the platform Xelon HQ. Technically, setting up MongoDB as a cluster on K8s means installing the three layers of MongoDB architecture using separate processes.

However, to configure the cluster on Xelon, you need to activate the environment in your system to support the MongoDB cluster. For this, you need to use the msiexec.exe command from the command line.

Installation of MongoDB Enterprise Edition

To set up the database in a cluster on Xelon, you need to use MongoDB 4.0 Enterprise Edition and higher. However, if you would like to use a different version of MongoDB then you need to choose a version together with the required documentation for successful configuration. To configure MongoDB Enterprise Edition:

Download the MongoDB Enterprise .msi installer here.

07_Deploy MongoDB_01

Run the window installer from the command interpreter depending on your operating system

07_Deploy MongoDB_02

In this case, we will be using windows OS. The command interpreter installs the MongoDB binaries which are then used to configure the cluster on Xelon. The binaries include MongoDB Compass

From the Command Interpreter, head to the directory which contains the .msi installation binary and run:

msiexec.exe /l*v mdbinstall.log  /qb /i mongodb-windows-x86_64-enterprise-4.4-signed.msi

To suppress the MongoDB Compass, you MUST explicitly include


argument clause.  Since we are setting the clause in the  Xelon HQ, you need to configure the Kubernetes. To do this, set up the Kubernetes cluster which will be responsible for deploying the database cluster.

Setting up MongoDB

Now that you have installed the MDB setup, you need to install the .yaml directories on the router and config servers as follows:

server: "https://explicitip/k8s/clusters/c-6n7xc"

07_Deploy MongoDB_03

For simplicity, this is referred to as the config server. Never use apt-get when installing MongoDB as there is no current version. Instead, use the following steps to configure it.


07_Deploy MongoDB_04

Note that the steps install Mongos (router), Mongod (config and shared server) as three separate packages. To achieve this you need to initiate three open firewall ports 27017, 27018, and 27019 between the servers.

  1. Config Server
  2. Log in to the designated config server
  3. Then, set up the three servers as shown below:
    • Edit config file
    • Start process
    • Check log for errors
    • Log into the shell to do further configuration

Why do we need secrets in pods?

Secrets are used for keeping and preserving applications/user/pass of a database, which can be further referenced by other container apps which is crucial to deploying a MongoDB application using Kubernetes.

Minimal yaml files needed

For successful setup, four kinds of files are required. The user can opt to run the commands separately or combine the four files into one.

Deployment yaml file

The deployment yaml file includes the container that are combined and pulled while the cluster deploys. It also contains crucial information including configured secrets, CPU resources, and location where the volume has been mounted.

kubectl --kubeconfig=config-e044b4259991.yaml --insecure-skip-tls-verify get nodes
- name: "k8s-technical-writer-cluster"
token: "kubeconfig-user-hvpzh:r57s2f6sqlqfmkmxmxmfznhqq5w5kfbvzns6z5fpns5rfdhfhllwn2"

Service yaml file

This file is needed to expose internal pods via some external port. Usually the port and target port are the same. The only port that needs to be configured is the “node port“ and it can be any ephemeral port.

Persistent Volume

This is used to allocate the persistent volume resource for MySQL from Kubernetes cluster


This is used for storing configuration .In our case we will use it for nqinx.

Creating and combining yaml files as demonstrated below

apiVersion: v1
kind: Config
- name: "k8s-technical-writer-cluster"
server: "https://explicitip/k8s/clusters/c-6n7xc"
certificate-authority-data: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJpVENDQ\

- name: "k8s-technical-writer-cluster"
token: "kubeconfig-user-hvpzh:r57s2f6sqlqfmkmxmxmfznhqq5w5kfbvzns6z5fpns5rfdhfhllwn2"

- name: "k8s-technical-writer-cluster"
user: "k8s-technical-writer-cluster"
cluster: "k8s-technical-writer-cluster"

current-context: "k8s-technical-writer-cluster"

07_Deploy MongoDB_05

The apiVersion refers to Kubernetes API resource version that you should use.

“Kind” specifies the type of cluster being config here.

In simple words, the cluster can be described as the data that helps to correctly identify the object, including a name string, server, and the certificate authority data.

Labels can be considered as key-value pairs for easy and fast querying and lookup later.

In this step, data is the key part. It contains the basic Nginx configuration when it is installed as standalone applications

The above config serves MongoDB index.php pages via:

Creating a MongoDB PVC on Kubernetes

To initiate the MongoDB cluster, we need to first create a MongoDB Persistent Volume Claim (PVC), which will be responsible for storing the cluster

kind: PersistentVolumeClaim
apiVersion: v1
name: k8s-technical-writer-mongo-cluster
annotations: xelon-ha-sc
- ReadWriteOnce
storage: 1Gi

$ kubectl create -f xelon-mongo-pvc.yaml
persistentvolumeclaim "xelon-mongo-pvc" created

Deploying MongoDB on Kubernetes

Now that we have a cluster to work on, let’s create MongoDB instance as a deployment object. In this example, we will deploy a single MongoDB cluster. Because Xelon provides an explicit synchronous replication for availability, then a single MongoDB cluster could be the best option to deploy in your Mongo database. Note: Xelon HQ also provides multiple replica sets.

apiVersion: apps/v1
kind: Deployment
name: mongo
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
replicas: 1
app: mongo
app: mongo
schedulerName: k8s-technical-writer
- name: mongo
image: mongo
imagePullPolicy: "Always"
- containerPort: 27017
- mountPath: /data/db
name: mongodb
- name: mongodb
claimName: xelon-mongo-pvc

$ kubectl create -f xelon-mongo-app.yaml
deployment.extensions "mongo" created

The deployment of the Mongo Database is defined and explicitly associated with the PVC,  xelon-mongo-pvc which was earlier created.


07_Deploy MongoDB_06

Remove MongoDB Windows Service

To kill/exit the MongoDB Cluster on Xelon K8s, you need to initiate the kill command to release the cluster from the server where it is located. To do this, you need to run sc.exe delete MongoDB command. The command will successfully release MongoDB cluster in the Xelon HQ.

If you have any question how to use MongoDB in the Xelon HQ please feel free to contact our support team!


What are your Feelings:

  • smiley
  • smiley
  • smiley

Leave a Reply

Your email address will not be published. Required fields are marked *