Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect MongoDB which is running on Kubernetes cluster through UI tools like MongoDB Compass or RoboMongo?

I have multiple instances of Mongo db deployed inside my kubernetes cluster through helm packages. They are running as a service, in NodePort. How do I connect to those Mongo db instances through UI tools like MongoDB Compass and RoboMongo from outside the cluster? Any help is appreciated.

like image 294
Shruthi Bhaskar Avatar asked Aug 06 '18 15:08

Shruthi Bhaskar


1 Answers

You can use kubectl port-forward to connect to MongoDB from outside the cluster.

Run kubectl port-forward << name of a mongodb pod >> --namespace << mongodb namespace >> 27018:27018.
Now point your UI tool to localhost:27018 and kubectl will forward all connections to the pod inside the cluster.

Starting with Kubernetes 1.10+ you can also use this syntax to connect to a service (you don't have to find a pod name first):
kubectl port-forward svc/<< mongodb service name >> 27018:27018 --namespace << mongodb namespace>>

like image 110
Oliver Avatar answered Sep 28 '22 03:09

Oliver