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 mongo:27***
Kubernetes exposes mongod on port 27017 within the Kubernetes container. The NodePort service exposes the mongod via port 30994 . NodePorts range from 30000 to 32767, inclusive. To connect to your deployment from outside of the Kubernetes cluster, run the mongod command with the external FQDN of a node as the --host flag.
If a node in the Kubernetes cluster has an external FQDN of ec2-54-212-23-143.us-west-2.compute.amazonaws.com, you can connect to this standalone instance from outside of the Kubernetes cluster using the following command: To obtain the external DNS of your Kubernetes cluster, you can run the following command:
Type LoadBalancer is usually used on cloud providers since they provide external load balancers for Kubernetes. So, in your case, NodePort is the easiest way to expose the Port. Here is an example of Service YAML: In line port: 27017, we specified your MongoDB port, it is also usually specified in Deployment for MongoDB.
Use Kubernetes to control fully managed MongoDB Atlas deployments on AWS, Azure, and GCP Kubernetes Operators are application-specific controllers that extend the Kubernetes API to create, configure, and manage instances of stateful applications such as databases.
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
mongo
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
You can use kubectl port-forward mypod 27017:27017
and then just connect your mongodb client to localhost:27017
.
If you want to stop, just hit Ctrl+C
on the same cmd window to stop the process.
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