MongoDB replica in multi-cluster environment

Hi all,

Is there a way to replicate MongoDB within 2 k8s clusters? I am currently using community k8s operator for MongoDB. I would like to create a replica in cluster A, sync data, make it primary and then decomission cluster B.

Unfortunately Cluster to Cluster sync is only available under a paid license - either Atlas or Enterprise.

I’m not aware of any other way to do this without simply exporting and then importing to the new cluster.

Would it be possible to have this process without a downtime? We have statefulset (mongodb) and doing blue/green k8s cluster upgrade.

To my knowledge, I should still be able to create separate mongo instance and then sync it with cluster. Just few additional steps are added. Am I correct?

You could do a mongodump and mongorestore without downtime. But it’s not ideal for failing over in that scenario since there’s likely to be writes between when you take the dump to when you complete it’s restore.

MongoSync (the tool behind cluster to cluster sync) is intended for that kind of purpose. But as I say it’s not licensed for Community.

Yes, I understand. MongoSync is cluster to cluster. However, as I understand I can create an instance and then sync it with cluster (replication within one cluster and another instance - not cluster to cluster). Am I wrong?

That should work. Assuming I understand correctly. And what I understand is that you have

1- replica-set-1where all the members are running on k8s-cluster-1
2- you want to add member-4 to replica-set-1 that runs on k8s-cluster-2
3- make member-4 primary once it has synced
4- 2 other members to replica-set-1 also running on k8s-cluster-2
5- finally, remove all members from replica-set-1 that runs on k8s-cluster-1

That should work on the mongo side. The other thing is how the application connects to your replica set. If you are using SRV and update all the DNS information correctly it should be fine. If it connects using member addresses of k8s-cluster-1, you have to update the connection string to include members of k8s-cluster-2.

Thank you, I had this in mind yet did not know how to do it in details

Perhaps you could tell how communication between mongodb would happen if parts of them are in separate k8s clusters?

You can’t span a single replica set over multiple Kubernetes clusters using the Community Operator. You could do it yourself… but that’s not something we have specific guidance on.

(As a side note the Enterprise Operator does support multi-Kubernetes-cluster replica sets.)

As for how communication would work between members of the replica set on different Kubernetes clusters, we recommend using a service mesh for communication between clusters, but there’s a number of options to establishing the networking.

You try to sell so hard it is not even ethical anymore. I was asking the member of community I replied to

Apologies if it came across as an attempt to sell!

While it’s not supported in the Community Operator, you might gain some insights from the guidance we offer for the Enterprise Operator. For example


I do not know enough about k8s routing to help you with this.

Thank you for your ideas regarding enterprise. However, I am not using it so the advise is not helpful for me.