Home > Mobile >  How to deploy Microservices with MongoDB dependency on Kubernetes?
How to deploy Microservices with MongoDB dependency on Kubernetes?

Time:04-01

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?

CodePudding user response:

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.

CodePudding user response:

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

  • Related