Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to openshift 3 mongodb from remote?

How do I connect to my Openshift 3 MongoDB with https://mongobooster.com/ from my local mac? The credentials from the pod do not work.

Pod: nodejs-mongo-persistent-1-rt6ch

Connected to MongoDB at: mongodb://userLorem:[email protected]:27017/sampledb
like image 668
fabian Avatar asked Sep 30 '17 10:09

fabian


2 Answers

Just fleshing out Graham's answer in case it may be of assistance (although I am not so much of an authority).

This worked for me in Robo 3T (formally RoboMongo) - a GUI for MongoDB administration.

The result was that I could use a GUI to remotely interact with a MongoDB instance on OpenShift.

Sanity / Data Checks and Environment Familiarisation

Assuming you have MongoDB running on OpenShift, to get relevant data go to:

Your Project > Resources > Secrets > mongodb > [ click reveal secret ]

Copy these values to a safe place if you haven't already:

database-admin-password: *****

database-name: sampledb

database-password: *****

database-user: *****

Assuming you have OpenShift CLI tools installed, you can then do the following to familiarize yourself with your project environment:

oc get pods

will return something like:

NAME                     READY     STATUS       RESTARTS   AGE
mongodb-1-XXXX5          1/1       Running      0          12h
my-node-app-10-build     0/1       Completed    0          10h
my-node-app-2-build      0/1       Init:Error   0          11h
my-node-app-8-cg2v2      1/1       Running      0          10h
my-node-app-9-build      0/1       Completed    0          10h

You can then rsh into your mongo pod with the following (replacing with your actual mongodb pod name):

oc rsh mongodb-1-XXXX5

Then run the mongo shell with the following (using the values you got from the console earlier):

// don't do this...
// normal user name, normal user password (won't allow you to run 'show dbs')
// mongo -u "database-user" -p "database-password" sampledb

// do this...
// admin user, admin user password (this lets you run 'show dbs' etc)
mongo -u "admin" -p "database-admin-password" admin

Setting Up Port Forwarding

The above steps made me feel more familiar with what I was working with, then I could look into port forwarding:

https://learn.openshift.com/introduction/port-forwarding

The relevant part regarding remote access to MongoDB on OpenShift is in step four:

To setup port forwarding between a local machine and the database running on OpenShift you use the oc port-forward command. You need to pass the name of the pod and details of the port the database service is using, as well as the local port to use.

The format for the command is:

oc port-forward <pod-name> <local-port>:<remote-port>

In my case, I did this:

oc port-forward mongodb-1-XXXX5 34000:27017

So this means:

The client listens on port 34000 locally and forwards to 27017 in the pod.

See: https://docs.openshift.com/online/dev_guide/port_forwarding.html

Remote GUI Settings

The settings I then defined in Robo 3T were:

Type: Direct Connection

Name: OpenShift MongoDB Instance

Address: localhost : 34000

And on Authentication tab...

Perform authentication: checked

Database: admin

Username: admin

Password: [ your database-admin-password ]

Auth Mechanism:

SCRAM-SHA-1

like image 68
user1063287 Avatar answered Oct 17 '22 03:10

user1063287


You need to use port forwarding. See the port forwarding tutorial at:

  • https://learn.openshift.com

The example is for PostgreSQL, but same principle.

like image 24
Graham Dumpleton Avatar answered Oct 17 '22 05:10

Graham Dumpleton