我想创建三台机器的MongoDB副本,需要指定这些机器的IP地址吗?但他们遇到了一个pod并拥有动态IP。如果你试图指定他说的DNS名称服务MongoDB
新配置XXXXX中没有主机描述副本集 app_replica映射到此节点
如何为c k8s配置MongoDB副本?
我为k8s使用DNS插件。 我尝试按如下方式初始化集群:
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)
配置服务:
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"
配置复制控制器:
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"
答案 0 :(得分:1)
您需要设置多个部署和服务。看看这个zookeeper示例 - https://gist.github.com/bprashanth/8160d0cf1469b4b125af95f697433934
您不依赖节点/机器IP。相反,您依赖于多个服务的稳定DNS名称。
答案 1 :(得分:1)