您可以在 MongoDB CustomResourceDefinition 中配置MongoDB资源以绑定到特定存储。The persistence 字段 in the MongoDB CustomResourceDefinition allows you to more precisely manage where Kubernetes 存储 the 日志 and 元数据 generated from MongoDB custom 资源.通过控制日志和元数据存储,可以更精细地控制管理生成的元数据并与之交互的进程。
您可以在MongoDB CustomResourceDefinition 中为每个组件配置持久性设置。这些设置允许您指定给定组件与一个或多个相关 PersistentVolume 资源之间的关系,这些资源存储MongoDB自定义资源的输出。
persistence设置指定与Kubernetes集群中MongoDB自定义资源托管对象关联的persistentVolumes的数量和存储容量。
先决条件
要为MongoDB 部署配置存储选项,您必须通过MongoDB Kubernetes Operator 部署MongoDB副本集,或者满足以下先决条件:
步骤
要创建单个PersistentVolume ,让给定组件在其中存储所有MongoDB CustomResourceDefinition 输出,请将该组件的persistence 定义为single 。要为组件的 data、journal 和 logs 创建不同的 PersistentVolume,请将组件的 persistence 定义为 multiple。
更新您的MongoDB自定义资源。
填充MongoDB CRD 定义的persistence部分,如以下示例所示:
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: my-sharded-cluster 6 spec: 7 shardCount: 2 8 mongodsPerShardCount: 3 9 mongosCount: 2 10 configServerCount: 3 11 version: "8.0.0" 12 service: my-service 13 type: ShardedCluster 14 15 persistent: true 16 17 configSrvPodSpec: 18 persistence: 19 single: true 20 21 shardPodSpec: 22 persistence: 23 multiple: 24 # if the child of "multiple" is omitted then the default size will be used. 25 # 16GB for "data", 1GB for "journal", 3GB for "logs" 26 data: 27 storage: "20Gi" 28 storageClass: standard # You must define a storageClass, as the Operator creates a PVC, which will only create an associated PV with a backing storageClass. 29 logs: 30 storage: "4Gi" 31 storageClass: standard 32 ...