我正在尝试使用 Minikube 中的 MongoDB Community Kubernetes Operator 部署 MongoDB 副本集。
我按照官方 GitHub 上的说明进行操作,所以:
- 安装 CRD
- 安装必要的角色和角色绑定
- 安装 Operator 部署 Replicaset
默认情况下,operator 将创建三个 pod,每个 pod 都自动链接到一个新的持久卷声明,该声明绑定到一个由 operator 创建的新持久卷(到目前为止一切都很好)。
但是,我希望将数据保存在特定的卷中,并安装在特定的主机路径中。因此,为了我需要创建三个持久卷,每个都安装到特定的主机路径,然后我想自动配置副本集,以便每个 pod 连接到其各自的持久卷(可能使用 matchLabels 选择器)。所以我通过应用以下文件创建了三个卷:
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongodb-pv-00
namespace: $NAMESPACE
labels:
type: local
service: mongo
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/mongodata/00"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongodb-pv-01
namespace: $NAMESPACE
labels:
type: local
service: mongo
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/mongodata/01"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongodb-pv-02
namespace: $NAMESPACE
labels:
type: local
service: mongo
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/mongodata/02"
然后我通过以下方式设置副本集配置文件,但仍然无法将 Pod 连接到卷:
apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
name: mongo-rs
namespace: $NAMESPACE
spec:
members: 3
type: ReplicaSet
version: "4.4.0"
persistent: true
podSpec:
persistence:
single:
labelSelector:
matchLabels:
type: local
service: mongo
storage: 5Gi
storageClass: manual
statefulSet:
spec:
volumeClaimTemplates:
- metadata:
name: data-volume
spec:
accessModes: [ "ReadWriteOnce", "ReadWriteMany" ]
resources:
requests:
storage: 5Gi
selector:
matchLabels:
type: local
service: mongo
storageClassName: manual
security:
authentication:
modes: ["SCRAM"]
users:
- ...
additionalMongodConfig:
storage.wiredTiger.engineConfig.journalCompressor: zlib
我在网上找不到任何文档,除了mongodb.com_v1_custom_volume_cr.yaml,以前有人遇到过这个问题吗?我怎样才能让它工作?