MongoDB工具 >MongoDB Kubernetes运营商 >部署MongoDB数据库资源 >编辑数据库资源 > 调整一个数据库资源的存储大小
在本页面
确保永久卷 使用的StorageClass和卷插件提供程序支持调整大小:
kubectl patch storageclass/<my-storageclass> --type='json' \ -p='[{"op": "add", "path": "/allowVolumeExpansion", "value": true }]'
如果您没有支持调整大小的StorageClass,请向Kubernetes管理员寻求帮助。
使用现有的数据库资源或使用持久性存储创建一个新的数据库资源。等待直到永久卷达到Running 状态。
Running
例
具有持久性存储的数据库资源将包括:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: <my-replica-set> spec: members: 3 version: 4.0.4 project: my-project credentials: my-credentials type: ReplicaSet podSpec: memory: 300M persistence: single: storage: 1G
从mongoKubernetes集群开始。
mongo
$kubectl exec -it <my-replica-set>-0 \ /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.0.4/bin/mongo
将数据插入test数据库。
test
<my-replica-set>:PRIMARY> use test switched to db test <my-replica-set>:PRIMARY> db.tmp.insert({"foo":"bar"}) WriteResult({ "nInserted" : 1 })
为整个副本集调用以下命令:
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资源。
kubectl delete sts --cascade=false <my-replica-set>
更新磁盘大小。打开您喜欢的文本编辑器,并进行与以下示例类似的更改:
要将副本的磁盘大小设置为2 GB,请将storage数据库资源规范中的值更改为 :
storage
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: <my-replica-set> spec: members: 3 version: 4.0.4 project: my-project credentials: my-credentials type: ReplicaSet podSpec: memory: 300M persistence: single: storage: 2G
用新的卷大小重新创建一个StatefulSet资源。
kubectl apply -f my-replica-set-vol.yaml
等待此StatefulSet达到Running状态。
调用以下命令:
kubectl rollout restart sts <my-replica-set>
新的Pod安装了调整大小的卷。
如果重复使用持久卷,则可以在持久卷中存储的数据库上找到在步骤2中插入的数据:
$ kubectl exec -it <my-replica-set>-1 \ /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.0.4/bin/mongo
<my-replica-set>:PRIMARY> use test switched to db test <my-replica-set>:PRIMARY> db.tmp.count() 1