I want to create MongoDB replica of the three machines, it needs to specify the IP-addresses of these machines? But they run into a pod's and have a dynamic IP. If you try to specify the DNS-name service MongoDB he says
No host described in new configuration XXXXX for replica set app_replica maps to this node
How to configure MongoDB replica for c k8s?
I use DNS-addons for k8s. And I try to initialize the cluster as follows:
var config = {
"_id" : "app_replica",
"members" : [
{
"_id" : 0,
"host" : "mongodb-node-01"
},
{
"_id" : 1,
"host" : "mongodb-node-02"
},
{
"_id" : 2,
"host" : "mongodb-node-03",
"arbiterOnly" : true
}
]
}
rs.initiate(config)
Config Service:
apiVersion: v1
kind: Service
metadata:
name: "mongodb-node-01"
labels:
app: "mongodb-node-01"
spec:
ports:
- port: 27017
targetPort: 27001
selector:
app: "mongodb-node-01"
Config Replication Controller:
apiVersion: v1
kind: ReplicationController
metadata:
name: "mongodb-node-01"
labels:
app: "mongodb-node-01"
spec:
replicas: 1
selector:
app: "mongodb-node-01"
template:
metadata:
labels:
app: "mongodb-node-01"
spec:
containers:
- name: "mongodb-node-01"
image: 192.168.0.139:5000/db/mongo
command:
- mongod
- "--replSet"
- "app_replica"
- "--smallfiles"
- "--noprealloc"
env:
- name: ENV
value: "prod"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
readOnly: false
volumes:
- name: mongo-persistent-storage
hostPath:
path: /data/mongo/mongodb-node-01
nodeSelector:
database: "true"
mongodb01: "true"