The Ops Manager, MongoDB Database, AppDB and Backup Daemon custom resources that comprise a standard Kubernetes Operator deployment are each deployed as Kubernetes statefulSets. The Kubernetes Operator supports increasing the storage associated with these specific resources by increasing the capacity of their respective Kubernetes persistentVolumeClaims when the underlying Kubernetes storageClass supports Kubernetes persistentVolume expansion.
根据特定的资源类型,您可以通过以下两种方式之一增加存储。 您可以手动增加存储,也可以利用Kubernetes Operator 的简易存储扩展功能。 下表说明了给定的自定义资源类型支持这两个过程中的哪一个。
自定义资源类型 | 手动存储扩展 | 轻松存储扩展 |
|---|---|---|
AppDB | ||
备份守护进程 | ||
MongoDB 数据库 | ||
MongoDB多集群 | ||
Ops Manager |
先决条件
存储类必须支持调整大小
确保持久卷使用的 StorageClass 和卷插件提供商程序支持调整大小:
kubectl patch storageclass/<my-storageclass> --type='json' \ -p='[{"op": "add", "path": "/allowVolumeExpansion", "value": true }]'
如果您没有支持调整大小的storageClass ,请向Kubernetes管理员寻求帮助。
轻松扩展存储
注意
简易扩展机制需要Kubernetes Operator 中包含的默认RBAC。 具体来说,它需要get 、 list 、 watch 、 patch和update persistantVolumeClaims 。 如果您自定义了任何Kubernetes Operator RBAC 资源,则可能需要调整权限,以允许Kubernetes Operator 调整Kubernetes集群中存储资源的大小。
此进程会导致Kubernetes集群中的MongoDB自定义资源滚动重启。
创建或标识持久性自定义资源。
使用现有的数据库资源或创建具有持久存储的新数据库资源。 等待持久卷进入Running状态。
例子
具有持久存储的数据库资源包括:
1 apiVersion: mongodb.com/v1 2 kind: MongoDB 3 metadata: 4 name: <my-replica-set> 5 spec: 6 members: 3 7 version: "8.0.0" 8 project: my-project 9 credentials: my-credentials 10 type: ReplicaSet 11 podSpec: 12 persistence: 13 single: 14 storage: "1Gi"
将数据插入资源提供服务的数据库。
Start
mongoin the Kubernetes cluster.kubectl exec -it <my-replica-set>-0 \ /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-8.0.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") }
使用新的存储值更新数据库资源。
重要
只能增加现有存储资源的磁盘大小,而不能减少。 减小存储大小会导致协调阶段出错。
更新磁盘大小。 打开您首选的文本编辑器并进行与此示例类似的更改:
例子
要将副本集的磁盘大小更新为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: "8.0.0" 8 project: my-project 9 credentials: my-credentials 10 type: ReplicaSet 11 podSpec: 12 persistence: 13 single: 14 storage: "2Gi" 使用新的卷大小更新MongoDB自定义资源。
kubectl apply -f my-updated-replica-set-vol.yaml 等待此 StatefulSet 达到
Running状态。
Validate that the Persistent Volume Claim has been resized.
如果重复使用持久卷,则可以在存储在持久卷中的数据库上找到在步骤 2中插入的数据:
kubectl describe mongodb/<my-replica-set> -n mongodb
以下输出表示正在处理您的 PVC 大小调整请求。
status: clusterStatusList: {} lastTransition: "2024-08-21T11:03:52+02:00" message: StatefulSet not ready observedGeneration: 2 phase: Pending pvc: - phase: PVC Resize - STS has been orphaned statefulsetName: multi-replica-set-pvc-resize-0 resourcesNotReady: - kind: StatefulSet message: 'Not all the Pods are ready (wanted: 2, updated: 1, ready: 1, current:2)' name: multi-replica-set-pvc-resize-0 version: ""
验证更新后的持久卷声明中是否存在数据。
If you reuse Persistent Volumes, you can find the data that you inserted in Step 2 on the databases stored in Persistent Volumes:
kubectl exec -it <my-replica-set>-1 \ /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-8.0.0/bin/mongo
<my-replica-set>:PRIMARY> use test switched to db test <my-replica-set>:PRIMARY> db.tmp.count() 1
手动扩展存储
创建或标识持久性自定义资源。
使用现有数据库资源或创建具有持久存储的新数据库资源。 等待持久卷进入Running状态。
例子
具有持久存储的数据库资源包括:
1 apiVersion: mongodb.com/v1 2 kind: MongoDB 3 metadata: 4 name: <my-replica-set> 5 spec: 6 members: 3 7 version: "8.0.0" 8 project: my-project 9 credentials: my-credentials 10 type: ReplicaSet 11 podSpec: 12 persistence: 13 single: 14 storage: "1Gi"
将数据插入资源提供服务的数据库。
Start
mongoin the Kubernetes cluster.kubectl exec -it <my-replica-set>-0 \ /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-8.0.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") }
修补每个持久性卷。
为整个副本集调用以下命令:
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
删除 StatefulSet。
注意
此步骤仅删除StatefulSet。Pod 保持不变并运行。
删除 StatefulSet 资源。
kubectl delete sts --cascade=false <my-replica-set>
使用新的存储值更新数据库资源。
更新磁盘大小。 打开您首选的文本编辑器并进行与此示例类似的更改:
例子
要将副本集的磁盘大小更新为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: "8.0.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 等待MongoDB自定义资源处于
Running状态。
验证更新后的持久卷声明中是否存在数据。
如果重复使用了持久卷,则可以在存储在持久卷中的数据库中找到您在步骤 2中插入的数据:
kubectl exec -it <my-replica-set>-1 \ /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-8.0.0/bin/mongo
<my-replica-set>:PRIMARY> use test switched to db test <my-replica-set>:PRIMARY> db.tmp.count() 1