How to connect to mongodb?

MY ENVIRONMENT: i’m running a new tutor installation of maple.2 on a kubernetes cluster which i haven’t made any configuration changes to the mongo environment. mongo is therefore running from a pod that was created by Tutor k8s. There’s a bastion server in the VPC in which the kubernetes cluster is running, and as best i can tell, all ports appear to be open between the bastion and the cluster.

MY OBJECTIVE: i want to migrate course content from my client’s previous open edx installation, so i created a tarball of a mongodump and stored it in an S3 bucket. now then, i want to restore this backup onto the mongo service that’s running in the kubernetes pod.

MY PROBLEM: i can connect to mongo from a shell on the mongodb container itself but if i try to connect from a terminal window connected to a bastion (an AWS EC2 ubuntu instance connected via ssh and launched inside the same VPC) then i get “Failed: error connecting to db server: no reachable servers”.

i’m new to kubernetes. what do i need to do in order to be able to see the host “mongodb” from outside of the kubernetes cluster?

1 Like

Hello @lpm0073,

Following would be my steps to restore MongoDB on tutor K8s:

  1. Get your dump file on bastion where the K8s cluster is running
  2. Get the name of your MongoDB pod by using the following command:
kubectl get pods -n openedx -o wide
  1. Copy your dump file to MongoDB pod using the following command:
kubectl cp dump.mongodb.5 openedx/mongodb-9rrcy8cb8d-tgwqr:/tmp/.
  1. Restore your openedx and cs_comments_service DB using the following commands:
# openedx DB restore command
kubectl exec -it mongodb-9rrcy8cb8d-tgwqr -n openedx -- mongorestore -h localhost --authenticationDatabase admin --drop -d openedx /tmp/dump.mongodb.5/openedx

# cs_comments_service restore command
kubectl exec -it mongodb-9rrcy8cb8d-tgwqr -n openedx -- mongorestore -h localhost --authenticationDatabase admin --drop -d cs_comments_service /tmp/dump.mongodb.5/cs_comments_service

I am also exploring tutor K8s, let me know if it works.

Note:
Here on tutor, edxapp DB is openedx.

2 Likes