While 3 instances is recommended by MongoDB for a more failure safe and highly available setup, I’m…
Thomas
1

Hello Thomas,

When a client application connect to a Mongo replicaset, the connection string mush include the ip (or hostname) of each of the replicas, 3 in the current example (https://docs.mongodb.com/manual/reference/connection-string/). If the replicas are defined within the same service, only the VIP (Virtual IP) of the service can be used to target the instances.

Also, when setting up a replicaset, the primary needs to be aware of the secondaries, which is something we can’t do if the 3 replicas are defined within the same service.

When defining a service, there should not be any links between the instances.

Hope this make sense, please let me know if you have any questions.