Cluster created in Rancher with Amazon EKS.
MongoDB replicaset was created as a catalog app in Rancher.
Services in the cluster can successfully connect the the database with this connection string.
mongodb://mongodb-replicaset.mongodb-replicaset.svc.cluster.local:27017/tradeit_system?replicaSet=rs
I want to view and edit data in the db. In a local db you can do it easily by the command mongo --port 27017
.
Similarly is there a way to connect to the one one on kubernetes. Either from the terminal or using an application like Robo 3t?
EDIT
The replicaset doesn't show when I do.
kubectl get deployments --all-namespace
kubectl get pods --all-namespaces
Show that it runs in 3 pods mongodb-replicaset-0, mongodb-replicaset-1, mongodb-replicaset-2.
kubectl get services -n <namespace>
. this will list the replicaset servicekubectl port-forward svc/mongodb-replicaset -n mongoNamespace 27018:27017
where
mongodb-replicaset = mongodb service name
mongoNamespace = namespace
and 27018 = your local port
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.
kubectl port-forward mongodb-replicaset-0 --namespace mongodb-replicaset 27017:27017
mongodb-replicaset-0
- pod that runs primary set.
This forwards the traffic to localhost:27017
on your machine.
Github discussion
Documentation on port-forward
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With