Navigation
This version of the documentation is archived and no longer supported.

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.

Considerations

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.

Procedure

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

1

Open the Topology view for your deployment.

Click Deployment in the left navigation.

2

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

3

Click Connect to this instance.

4

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

5

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

Example

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:

<k8s-pod-name>.<k8s-internal-service-name>.<k8s-namespace>.<cluster-name>