MongoDB data replication in Kubernetes

3/23/2017

I've been configuring pods in Kubernetes to hold a mongodb and golang image each with a service to load-balance. The major issue I am facing is data replication between databases. Replication controllers/replicasets do not seem to do what the name implies, but rather is a blank-slate copy instead of a replica of existing/currently running pods. I cannot seem to find any examples or clear answers on how Kubernetes addresses this, or does it even?

For example, data insertions being sent by the Go program are going to automatically load balance to one of X replicated instances of mongodb by the service. This poses problems since they will all be maintaining separate documents without any relation to one another once Kubernetes begins to balance the connections among other pods. Is there a way to address this in Kubernetes, or does it require a complete re-write of the Go code to expect data replication among numerous available databases?

Sorry, I'm relatively new to Kubernetes and couldn't seem to find much information regarding this.

-- Henry Henderson
kubernetes
mongodb

1 Answer

3/23/2017

You're right, a replica set is not a replica of another container, it's just a container with the same configuration spun up within the same logical unit.

A replica set (or deployment, which is the resource you should be using now) will have multiple pods, and it's up to you, the operator, to configure the mongodb part.

I would recommend reading this example of how to set up a replica set with multiple mongodb containers:

https://medium.com/google-cloud/mongodb-replica-sets-with-kubernetes-d96606bd9474#.e8y706grr

-- jaxxstorm
Source: StackOverflow