此版本的文档已存档,且不再支持此版本的MongoDB Enterprise Kubernetes Operator。
MongoDB Enterprise Kubernetes Operator 已弃用。新的 MongoDB Controllers for Kubernetes Operator 取代了MongoDB Enterprise Kubernetes Operator。第一个版本的 Controllers for Kubernetes Operator 在功能上等同于 v1.33 的Enterprise Kubernetes Operator。有关此更改的更多信息以及迁移到新 Operator 的指导,请参阅第一个新版本的发布说明。MongoDB Enterprise Kubernetes Operator 的未来版本将不会再发布。根据现有的一年支持政策,每个版本都将结束生命周期。请迁移到Kubernetes Operator 的控制器以获得持续支持。
先决条件
存储类必须支持调整大小
确保持久卷使用的 StorageClass 和卷插件提供商程序支持调整大小:
kubectl patch storageclass/<my-storageclass> --type='json' \ -p='[{"op": "add", "path": "/allowVolumeExpansion", "value": true }]'
如果您没有支持调整大小的 StorageClass,请向 Kubernetes 管理员寻求帮助。
步骤
1
创建或标识持久性自定义资源。
使用现有数据库资源或创建具有持久存储的新数据库资源。 等待持久卷进入 Running状态。
例子
具有持久存储的数据库资源包括:
1 apiVersion: mongodb.com/v1 2 kind: MongoDB 3 metadata: 4 name: <my-replica-set> 5 spec: 6 members: 3 7 version: "4.4.0" 8 project: my-project 9 credentials: my-credentials 10 type: ReplicaSet 11 podSpec: 12 persistence: 13 single: 14 storage: "1Gi"
2
将数据插入资源提供服务的数据库。
在 Kubernetes 集群中启动
mongo。kubectl exec -it <my-replica-set>-0 \ /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.4.0/bin/mongo 将数据插入
test数据库。<my-replica-set>:PRIMARY> use test switched to db test <my-replica-set>:PRIMARY> db.tmp.insertOne({"foo":"bar"}) { "acknowledged" : true, "insertedId" : ObjectId("61128cb4a783c3c57ae5142d") }
3
修补每个持久性卷。
为整个副本集调用以下命令:
kubectl patch pvc/"data-<my-replica-set>-0" -p='{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}' kubectl patch pvc/"data-<my-replica-set>-1" -p='{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}' kubectl patch pvc/"data-<my-replica-set>-2" -p='{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}'
等待每个持久卷声明达到以下条件:
- lastProbeTime: null lastTransitionTime: "2019-08-01T12:11:39Z" message: Waiting for user to (re-)start a pod to finish file system resize of volume on node. status: "True" type: FileSystemResizePending
4
删除 StatefulSet。
注意
此步骤仅删除StatefulSet。Pod 保持不变并运行。
删除 StatefulSet 资源。
kubectl delete sts --cascade=false <my-replica-set>
5
使用新的存储值更新数据库资源。
更新磁盘大小。 打开您首选的文本编辑器并进行与此示例类似的更改:
例子
要将副本集的磁盘大小更新为 2 GB,请更改数据库资源规范中的
storage值:1 apiVersion: mongodb.com/v1 2 kind: MongoDB 3 metadata: 4 name: <my-replica-set> 5 spec: 6 members: 3 7 version: "4.4.0" 8 project: my-project 9 credentials: my-credentials 10 type: ReplicaSet 11 podSpec: 12 persistence: 13 single: 14 storage: "2Gi" 使用新的卷大小重新创建StatefulSet资源。
kubectl apply -f my-replica-set-vol.yaml 等待此 StatefulSet 达到
Running状态。