Quick way to dump data from MongoDB running on Kubernetes cluster.

Doing tasks, that normally were quite easy on bare-metal non-containerized environment could become challenging when the same software is running under such orchestrator as Kubernetes. All the old fashioned CLI one liners are becoming harder to use.

Here’s a simple snippet we have used to dump data from db database and account collection under Kubernetes cluster.

kubectl -nmongo-replicaset -it exec mongo-replicaset-mongodb-replicaset-1 -- bash -c 'mongoexport -d db -hmongo-svc.mongo-replicaset -c account' | grep '"_id"'

and that is it … as you can see this is dump to stdout variant. Unfortunately mongoexport in such situation is throwing to stdout some debug information that could not be turned off easily, that’s why the results are piped through grep that is looking for “_id” field in our case.

Please amend it accordingly ! It should be easy !

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *