2
  1. Suppose we're using Kubernetes Deployments to host MongoDB.
    I know that Deployments suppose their pods are identical, and the corresponding service divides requests between the pods regardless of which pod is which.

    • Does this yield data inconsistency?
    • Or will mongo be run in its Replication manner, where one pod becomes Primary (& accepts write/read requests) and others become Secondary (& answer read requests).
  2. Suppose we're using Kubernetes StatefulSets to host MongoDB.
    Naturally, there's a service dividing request between stateful pods.
    Now in my application server, should I manually send Write requests to the Primary node? Or will it be handled by MongoDB itself? If so, how does MongoDB keeps the consistency? Where do the stateful pods get notified about each other and by who?

I suppose one scenario would be that my request gets sent to any pod randomly, If that pod can handle it (i.e. read request), it will do so. Otherwise (write request), the pod will send the request to the Primary Pod.

But that seems slow and inefficient and slow, doesn't it? Sending requests randomly hoping they would reach the correct place on the first try.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Danial
  • 362
  • 4
  • 18
  • "Or will mongo be run in its Replication manner...?" Kubernetes isn't magic: Mongo will only run in replication mode if you *explicitly configure it to do so*. You need to implement the same configuration you would need if you were running outside of kubernetes. MongoDB provides a [Kubernetes operator](https://www.mongodb.com/docs/kubernetes-operator/master/) to manage this sort of configuration. – larsks Jul 02 '22 at 14:10

0 Answers0