Connect to a MongoDB Database Resource from Inside Kubernetes

The following procedure describes how to connect to a MongoDB resource deployed by Kubernetes from inside of the Kubernetes cluster.


You must be able to connect to the host and port where you deployed your Kubernetes resource. To learn more about connecting to your deployment, see Connect to a MongoDB Process.


Perform the following steps in the Ops Manager or Cloud Manager application, depending on where your clusters are hosted:


Open the Topology view for your deployment.

Click Deployment in the left navigation.


Click ellipsis icon for the deployment to which you want to connect.


Click Connect to this instance.


Copy the connection command displayed in the Connect to your Deployment dialog.


Run the connection command in a terminal to connect to the deployment.


To connect to a sharded cluster resource named shardedcluster, you might use the following connection string:

mongo --host shardedcluster-mongos-0.shardedcluster-svc.mongodb.svc.cluster.local --port 27017

When connecting to a resource from inside of Kubernetes, the hostname to which you connect has the following form: