Hi Sebastian,
I’m planning on migrating from 1 mongodb instance to 3 instances (replica set) on a single node.
I was reading the docs and came across the following in the forums:
The cluster (aka replica set) is hosted in kubernetes. When I started with the replica set it was configured with a sidecar. This sidecar is a special container which scans kubernetes for MongoDB instances and connects them to a replica set. It was the way to go a few years ago, but is not recommended anymore, because during updates and down times the replica set gets reconfigured all the time, making updates much harder in some cases. The idea of this sidecar is to make scaling easier, as you can increase the number of nodes and everything will be configured automatically. But in practice this does almost never happens.
The sentence
It was the way to go a few years ago, but is not recommended anymore
caught my attention.
-
What do I use today instead of the Sidecar (cvallance/mongo-k8s-sidecar)?
-
When using a replica set do I have to use 3 nodes or can I use just 1 node? The reason I ask is because I don’t want to pay for more than 1 node at the moment. I don’t have that much traffic and it would be a waste of money paying for 3 nodes.
-
How would I configure my connection string if I were to use only 1 node (if I were to use cvallance/mongo-k8s-sidecar)?
Currently I have it configured like this (I use 1 node and 1 StatefulSet replica):
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 1
.
.
.
.
- name: ASSETSTORE__MONGODB__CONFIGURATION
value: "mongodb://mongodb-sts-0.mongodb-svc:27017/"
- name: EVENTSTORE__MONGODB__CONFIGURATION
value: "mongodb://mongodb-sts-0.mongodb-svc:27017/"
- name: STORE__MONGODB__CONFIGURATION
value: "mongodb://mongodb-sts-0.mongodb-svc:27017/"
.
.
.
Would the following be the correct configuration for the replicas and connection strings?
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 3
.
.
.
.
- name: ASSETSTORE__MONGODB__CONFIGURATION
value: "mongodb://mongodb-sts-0.mongodb-svc,mongodb-sts-1.mongodb-svc,mongodb-sts-2.mongodb-svc:27017/"
- name: EVENTSTORE__MONGODB__CONFIGURATION
value: "mongodb://mongodb-sts-0.mongodb-svc,mongodb-sts-1.mongodb-svc,mongodb-sts-2.mongodb-svc:27017/"
- name: STORE__MONGODB__CONFIGURATION
value: "mongodb://mongodb-sts-0.mongodb-svc,mongodb-sts-1.mongodb-svc,mongodb-sts-2.mongodb-svc:27017/"
Thanks!