我试图通过创建副本使我现有的 mongodb 具有高可用性。为了执行它,我参考了输入链接描述here
以下是我的有状态集
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: skeleton-mongodb
spec:
serviceName: skeleton-mongodb
replicas: 3
selector:
matchLabels:
app: skeleton-mongodb
template:
metadata:
labels:
app: skeleton-mongodb
spec:
containers:
- name: mongodb
image: mongo:4
resources:
requests:
memory: 250Mi
cpu: 100m
limits:
memory: 500Mi
ports:
- containerPort: 27017
name: mongo
args:
- "--bind_ip_all"
- "--replSet"
- rs0
volumeMounts:
- name: skeleton-mongodb-data
mountPath: /data/db
- name: skeleton-mongodb-init
mountPath: /docker-entrypoint-initdb.d
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
configMapKeyRef:
name: skeleton
key: mongo_root-username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: skeleton
key: mongodb_root-password
- name: MONGO_INITDB_DATABASE
valueFrom:
configMapKeyRef:
name: skeleton
key: mongo_db
- name: MONGO_USERNAME
valueFrom:
configMapKeyRef:
name: skeleton
key: mongo_username
- name: MONGO_USER_PASSWORD
valueFrom:
secretKeyRef:
name: skeleton
key: mongodb_user-password
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "app=skeleton-mongodb"
- name: MONGODB_DATABASE
valueFrom:
configMapKeyRef:
name: skeleton
key: mongo_db
- name: MONGODB_USERNAME
valueFrom:
configMapKeyRef:
name: skeleton
key: mongo_username
- name: MONGODB_PASSWORD
valueFrom:
secretKeyRef:
name: skeleton
key: mongodb_user-password
volumes:
- name: skeleton-mongodb-init
configMap:
name: common-mongodb-init
volumeClaimTemplates:
- metadata:
name: skeleton-mongodb-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: managed-premium
当我尝试查找哪个 pod 是我的主人时,我无法找到任何作为主人的 pod。
for ((i = 0; i < 3; ++i));
do
kubectl exec --namespace default skeleton-mongodb-$i -- sh -c 'mongo --eval="printjson(rs.isMaster())"';
done
我要买所有 3 个豆荚
{
"ismaster" : false,
"secondary" : false,
"info" : "Does not have a valid replica set config",
"isreplicaset" : true,
....
"readOnly" : false,
"ok" : 1
}
不确定我是否遗漏了什么