0

I'm deploying a simple Flask app using MongoDB in different VMs. For that I configured 2 config servers, 2 mongos instances and 2 shards with 2 replicas each (all of this in different VMs).

My question is simple, what is the difference between doing it this way (using 8 VMs without K8s) or doing it with a single VM and using Kubernetes to handle it all?

PedroG
  • 33
  • 6

1 Answers1

0

The reason why you deploy multiple instances of each of these components is to increase your availability and tolerance to handle fault.

What you want to achieve is to spread those 8 servers across as many physical machines as you can. Ideally each of these components that you run multiples of (e.g. the config servers) should not run on the same physical machine.

If you run the 8 VMs on a single physical machine or deploying 8 Kubernetes pods on a k8s cluster of one physical machine, you are not gaining anything in terms of fault tolerance or increased availability of your cluster.

In that case you would only gain the benefits of using an elaborate orchestrator like kubernetes to manage your containers.

thomas
  • 2,580
  • 1
  • 22
  • 28
  • Ok so imagining I have access to 8 different physical machines, is there any advantage of manually configuring the MongoDB cluster like I did and deploying each of the VMs in a different physical machine? Or would it be better to simply deploy a Mongo image on Kuberentes and have replicas on each physical machine? – PedroG Jul 10 '22 at 15:34
  • If I had a scenario as you described in your comment, I would highly recommend to set it up as a kubernetes cluster ans deploy all the components you mentioned in your question as pods and let k8s handle the spread across as many physical machines. It will also ensure that you always have the desired amount of replicas per component running! – thomas Jul 10 '22 at 15:40
  • Alright thanks, and does it make sense to keep the 2 replicas of config servers, and mongos, etc? Because Kubernetes will make the replicas anyways – PedroG Jul 10 '22 at 15:50
  • Yes, let k8s handle that. Specify 1 deployment for the each mongodb component and set the replica factor to your desired count – thomas Jul 10 '22 at 16:06
  • It should be noted, the main reason to deploy a MongoDB sharded cluster is to **distribute** the load across several (physical) machines, see https://stackoverflow.com/questions/11707879/difference-between-scaling-horizontally-and-vertically-for-databases – Wernfried Domscheit Jul 11 '22 at 06:09