Multiple pods using same database on kubernetes
K

1

6

I would like to know if it is possible for multiple pods in the same Kubernetes cluster to access a database which is configured using persistent volumes on a Google cloud persistent disk.

Currently I am building a microservices achitecture web app which has 3 node apis in different pods all accessing the same database. So how do I achieve this with kubernetes.

Kindly let me know if my architecture is right as well

Kitts answered 30/12, 2018 at 14:56 Comment(4)
This architecture is reasonable: as long as the database can handle the expected number of incoming connections, and the credentials are configured correctly in the pods, there should be no issue accessing the database with all APIs. Are there any specific concerns that you'd had about your design decisions here?Labellum
Are you talking about a networked database like Postgres or MySQL, or some kind of local file database like Sqlite or BDB?Murguia
I am using a mongo db @coderanger. I also want to access the database outside the cluster as well. So I want it to be highly availableKitts
MongoDB (the company) offers an operator (a custom Kubernetes controller), probably start with that.Murguia
M
3

You can certainly connect multiple node-based app pods to the same database. It is sometimes said that microservices shouldn't share a database but this depends on what your apps are doing, the project history and the extent to which you want the parts to be worked on separately.

There are questions you have to answer about running databases at scale, such as your future load and whether you want to use relational databases if you're going to try to span availability zones. And there are some specific to kubernetes, especially around how you associate DB Pods to data. See https://mcmap.net/q/1915017/-run-database-as-docker-container-or-on-a-bare-metal-server. Another popular option is to use a managed DB service from a cloud provider. If you do run the DB in k8s then I'd suggest looking for a helm chart or looking at an operator, such as the kubeDB operator, to avoid crafting the kubernetes descriptors yourself and to get more guidance on running the DB and setting it up.

If it's a new project and you've not used k8s before then you'll also have to decide where to host your code, your docker images and your deployment descriptors and how to setup your CI pipelines. If you've not got answers to these questions already then I'd suggest looking at Jenkins-X as it will provide you with out of the box defaults for a whole cluster and CI setup and a template ('build pack') for building node apps and deploying them to staging and prod environments through a pipeline.

Madlin answered 31/12, 2018 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.