Access to Mongodb in Kubernetes
I created a Mongodb service according to the Kubernetes tutorial.
Now my question is how do I gain access to the database itself, with a client like Robomongo or similar clients? Just for making backups or exploring what data have been entered.
The mongo-pod and service only have an internal endpoint, and a single mount.
Is there any way to safely access this instance with no public endpoint?
Internally URI is
You can use
kubectl port-forward mypod 27017:27017 and then just connect your mongodb client to
If you want to stop, just hit
Ctrl+C on the same cmd window to stop the process.
Connect to a MongoDB Database Resource from Outside Kubernetes, Prerequisite¶. For your databases to be accessed outside of Kubernetes, they must run one of the following versions of MongoDB: 3.6.17 or later Procedure ¶. 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. ¶. Click Connect to this instance . ¶. Copy the connection command displayed in the Connect to your Deployment dialog. ¶.
The kubernetes cmd-line tool provides this functionality as @ainlolcat stated
kubectl get pods
Retrieves the pod names currently running and with:
kubectl exec -i mongo-controller-* bash
you get a basic bash, which lets you execute
to get into the database to create dumps, and so on. The bash is very basic and has no features like completion and so on. I have not found a solution for better shell but it does the job
Connect to a MongoDB Database Resource from Inside Kubernetes , Deploy and Configure MongoDB Database Resources >; Access Database how to connect to a MongoDB resource deployed by Kubernetes from inside of the To connect to your Kubernetes Operator-deployed MongoDB sharded cluster resource from outside of the Kubernetes cluster: 1 Open your sharded cluster resource YAML file. ¶
when you create a service in kubernetes you give it a name, say for example "mymongo". After the service is created then
The DNS service of kubernetes (by default is on) will ensure that any pod can discover this servixe simply by its name. so you can set your uri like
In addition the service IP and port will be set as environment variables at the running pod.
I have in fact wrote a blog that show a step by step example of an app with nodejs web server and mongo that can explain further
How to expose and access MongoDb ports in Kubernetes?, In Kubernetes, if you want to expose a Port to the outside world, you can use Service with Type NodePort or LoadBalancer. Type LoadBalancer Or it can be skipped during the creation, in that case, Kubernetes assigns the port number automatically, and you can find it using kubectl describe service mongodb-service or kubectl get service mongodb-service -o yaml commands. After that, you can use any client, e.g. RoboMongo, to reach you MongoDB.
Running a MongoDB Database in Kubernetes with StatefulSets, 1. Overview. Google Container Engine makes it easy to run docker containers in the cloud. Google Container Engine uses Kubernetes, an open source The MongoDB Enterprise Operator for Kubernetes works with MongoDB Ops Manager or MongoDB Cloud Manager and provides your Kubernetes environment with the following benefits: Deploy, scale and automate MongoDB clusters of any type or size from standalone to sharded clusters. Enforce standardized
Running MongoDB on Kubernetes with StatefulSets, directly access the pods! This is perfect for creating MongoDB replica sets, because our app needs to connect to all of the MongoDB nodes Deploy MongoDB Resources Using Kubernetes¶ Deploy a Replica Set Using Kubernetes Use Ops Manager and the Kubernetes Operator to deploy a managed replica set. Deploy a Sharded Cluster Using Kubernetes Use Ops Manager and the Kubernetes Operator to deploy a managed sharded cluster. Deploy a Standalone Using Kubernetes
Connect MongoDB Hosted in kubernetes cluster, If you are planning to host your mongo instance on kubernetes cluster with ClusterIP As we don't want that outside world to access our mongodb , we created You can create and manage your MongoDB replica set natively in Kubernetes, without the need for scripts and Makefiles. Let’s take a look how. Note: StatefulSets are currently a beta resource.