1

CONTEXT: I have been learning Kubernetes and trying to get some hands-on experience. I have been using AKS to abstract the complexity of having to deal with the control plane (and because I have a free student azure account). I am deploying a NodeJS app that connects to the MongoDB database. So far the deployment has been successful but I am using MongoDB Atlas and connecting to it.

Based on the little I have learned about Stateful sets, the MongoDB Atlas service seems a lot easier and more convenient but my question is, when would it be a better idea to consider deploying a stateful set with MongoDB database? (running on the pod) What's more cost-effective? More easily scalable?

I realize the questions might be a little bit vague but I am just getting started with Kubernetes..

disclaimer: This is not a production application, just something simple I am using to learn K8S

  • Does this answer your question? [Why StatefulSets? Can't a stateless Pod use persistent volumes?](https://stackoverflow.com/questions/41732819/why-statefulsets-cant-a-stateless-pod-use-persistent-volumes) – CSharpRocks Mar 09 '22 at 21:53

2 Answers2

0

Official docs docs uses statefullset and that would make sense. Generally all DB kind of applications deployed as statefullset. Because there can be states that nodes are not sync with each other and that would create data inconsistencies between nodes(mongodb nodes not kubernetes).

You can deploy MongoDB as deployment. I have seen it deployed. But most clients use a connection string to connect(a string of multiple node addresses). And since kubernetes exposes statefullsets with headless services you should be okay.

Furkan
  • 352
  • 3
  • 12
0

For learning purpose, I advice you to deploy your MongoDB in a StatefulSet. Then you can learn how it works and what problem you could encounter with this Kubernetes object.

For production application, I advice to never deploy a database in a StatefulSet if you don't need it. In fact, StatefulSet will come with a lot of problematics that you might not need to manage.

Sometimes, companies rules restrict to host their data on external company storage.

To know if you need to put your database in a StatefulSet, the question I try to answer is:

  • Should my DB be hosted on premise (for privacy)?
  • Should my DB be scalable?
  • Should my DB be updated frequently?

You can find a list of pros/cons on the documentation.

Jérôme
  • 56
  • 1
  • 5