0

I have 2 API backends Microservices in which each Microservice has MongoDB database. I want to deploy 2 or more instances of each of these in Kubernetes cluster on Cloud provider such as AWS.

Each instance of Microservice runs as a container in a Pod. Is it possible to deploy MongoDB as another container in the same Pod? Or what is the best practice for this use case?

If two or more instances of the same Microservice are running in different Pods, do I need to deploy 2 or more instances of MongoDB or single MongoDb is referenced by the multiple instances of the same Microservice? What is the best practice for this use case?

Each Microservice is Spring Boot application. Do I need to do anything special in the Spring Boot application source code just because it will be run as Microservice as opposed to traditional Spring Boot application?

1
  • 1
    I would recommend not hosting your data layer (mysql, mongodb, etc) in kubernetes, at least at first. Running stateful application brings along a lot of challenges in k8s that you don't have with stateless spring boot services. Commented Mar 31, 2022 at 21:52

2 Answers 2

2

Each instance of Microservice runs as a container in a Pod. Is it possible to deploy MongoDB as another container in the same Pod?

Nope, then your data would be gone when you upgrade your application.

Or what is the best practice for this use case?

Databases in a modern production environment are run as clusters - for availability reasons. It is best practice to either use a managed service for the database or run it as a cluster with e.g. 3 instances on different nodes.

If two or more instances of the same Microservice are running in different Pods, do I need to deploy 2 or more instances of MongoDB or single MongoDb is referenced by the multiple instances of the same Microservice?

All your instances of the microservice should access the same database cluster, otherwise they would see different data.

Each Microservice is Spring Boot application. Do I need to do anything special in the Spring Boot application source code just because it will be run as Microservice as opposed to traditional Spring Boot application?

Spring Boot is designed according to The Twelve Factor App and hence is designed to be run in a cloud environment like e.g. Kubernetes.

Sign up to request clarification or add additional context in comments.

Comments

0

Deploy mongodb pod as a statefulset. refer below helm chart to deploy mongodb. https://github.com/bitnami/charts/tree/master/bitnami/mongodb

Using init container you can check inside springboot pod to check if the mongodb is up and running then start the springboot container. Follow the below link for help How can we create service dependencies using kubernetes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.