Deploy MongoDB on OpenShift using Helm


This is yet another blog post on deploying Blahblahblah on OpenShift and this time its MongoDB. In this post you will learn deployment of MongoDB on OpenShift using Helm Chart.

Lets’ get started

oc new-project ksingh
helm repo add bitnami
helm install mongodb bitnami/mongodb --set podSecurityContext.fsGroup="",containerSecurityContext.runAsUser="1001080001",podSecurityContext.enabled=false,architecture=replicaset,auth.replicaSetKey=$MONGODB_REPLICA_SET_KEY,auth.rootPassword=$MONGODB_ROOT_PASSWORD
export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace ksingh mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)
kubectl run --namespace ksingh mongodb-client --rm --tty -i --restart='Never' --env="MONGODB_ROOT_PASSWORD=$MONGODB_ROOT_PASSWORD" --image --command -- bash
## Option-1 Using host addres
mongo admin --host "mongodb-0.mongodb-headless.ksingh.svc.cluster.local:27017,mongodb-1.mongodb-headless.ksingh.svc.cluster.local:27017" --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD
## Option-2 Using MongoDB URI
mongo "mongodb://mongodb-0.mongodb-headless.ksingh.svc.cluster.local:27017,mongodb-1.mongodb-headless.ksingh.svc.cluster.local:27017" --authenticationDatabase admin  -u root -p $MONGODB_ROOT_PASSWORD
use mydb[
    title: "MongoDB to Kafka testing",
    description: "Debezium connector",
    by: "Karan",
    url: "",
    tags: ["mongodb", "debezium", "ROSAK"],
    likes: 100
show dbs

Exit the mongodb client container

  • If you want to connect to MongoDB cluster from localhost, then forward to port
kubectl port-forward service/mongodb-external-0 27017 &
mongo --host --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD
# MongoDB Compass > New Connection



Exit mobile version