<p>Cluster created in Rancher with Amazon EKS.</p>

<p>MongoDB replicaset was created as a catalog app in Rancher.</p>

<p>Services in the cluster can successfully connect the the database with this connection string.</p>

<p><code>mongodb://mongodb-replicaset.mongodb-replicaset.svc.cluster.local:27017/tradeit_system?replicaSet=rs</code></p>

<p>I want to view and edit data in the db. In a local db you can do it easily by the command <code>mongo --port 27017</code>. </p>

<p>Similarly is there a way to connect to the one one on kubernetes. Either from the terminal or using an application like Robo 3t?</p>

<p>EDIT</p>

<p>The replicaset doesn't show when I do.</p>

<p><code>kubectl get deployments --all-namespace</code></p>

<p><code>kubectl get pods --all-namespaces</code></p>

<p>Show that it runs in 3 pods mongodb-replicaset-0, mongodb-replicaset-1, mongodb-replicaset-2.</p>

enzio902
<ol>
<li>run <code>kubectl get services -n &lt;namespace&gt;</code>. this will list the replicaset service</li>
<li>execute <code>kubectl port-forward svc/mongodb-replicaset -n mongoNamespace 27018:27017</code></li>
</ol>

<p>where </p>

<p><strong>mongodb-replicaset</strong> = mongodb service name</p>

<p><strong>mongoNamespace</strong> = namespace</p>

<p>and <strong>27018</strong> = your local port</p>

<p>As best practice, you should always connect on services not on pods. Since pods are automatically recreated/restarted, it will give you a new pod name. Connecting to a service saves you from reconnecting and finding the primary pod of your mongodb replicaset.</p>
