|
| 1 | +# Resize PVC Resources # |
| 2 | + |
| 3 | +Resizing the [Persistent Volume Claim (PVC)](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) resources for your Community Kubernetes Operator replica sets using the [StatefulSet](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) is [not yet possible](https://github.com/kubernetes/enhancements/pull/3412). Instead, follow these steps to resize the PVC resource for each replica set and recreate the StatefulSet. |
| 4 | + |
| 5 | +1. Enable your storage provisioner to allow volume expansion by setting `allowVolumeExpansion` in the [StorageClass](https://kubernetes.io/docs/concepts/storage/storage-classes/) to `true`. For example: |
| 6 | + |
| 7 | + ``` |
| 8 | + kubectl patch storageclass/<my-storageclass> --type='json' -p='[{"op": "add", "path": "/allowVolumeExpansion", "value": true }]' |
| 9 | + ``` |
| 10 | + |
| 11 | +1. If you don't already have a `MongoDBCommunity` resource with custom storage specified, create one. For example: |
| 12 | + |
| 13 | + ```yaml |
| 14 | + --- |
| 15 | + apiVersion: mongodbcommunity.mongodb.com/v1 |
| 16 | + kind: MongoDBCommunity |
| 17 | + metadata: |
| 18 | + name: example-mongodb |
| 19 | + spec: |
| 20 | + members: 3 |
| 21 | + type: ReplicaSet |
| 22 | + version: "6.0.5" |
| 23 | + statefulSet: |
| 24 | + spec: |
| 25 | + volumeClaimTemplates: |
| 26 | + - metadata: |
| 27 | + name: data-volume |
| 28 | + spec: |
| 29 | + resources: |
| 30 | + requests: |
| 31 | + storage: 50Gi |
| 32 | + ... |
| 33 | + ``` |
| 34 | + |
| 35 | +1. Patch the PVC resource for each replica set. |
| 36 | + |
| 37 | + ``` |
| 38 | + kubectl patch pvc/"data-volume-<my-replica-set>-0" -p='{"spec": {"resources": {"requests": {"storage": "100Gi"}}}}' |
| 39 | + kubectl patch pvc/"data-volume-<my-replica-set>-1" -p='{"spec": {"resources": {"requests": {"storage": "100Gi"}}}}' |
| 40 | + kubectl patch pvc/"data-volume-<my-replica-set>-2" -p='{"spec": {"resources": {"requests": {"storage": "100Gi"}}}}' |
| 41 | + ``` |
| 42 | + |
| 43 | +1. Scale the Community Kubernetes Operator to `0`. |
| 44 | + |
| 45 | + ``` |
| 46 | + kubectl scale deploy mongodb-kubernetes-operator --replicas=0 |
| 47 | + ``` |
| 48 | + |
| 49 | +1. Remove the StatefulSet without removing the Pods. |
| 50 | + |
| 51 | + ``` |
| 52 | + kubectl delete sts --cascade=orphan <my-replica-set> |
| 53 | + ``` |
| 54 | + |
| 55 | +1. Remove the `MongoDBCommunity` resource without removing the Pods. |
| 56 | + |
| 57 | + ``` |
| 58 | + kubectl delete mdbc --cascade=orphan <my-replica-set> |
| 59 | + ``` |
| 60 | + |
| 61 | +1. Scale the Community Kubernetes Operator to `1`. |
| 62 | + |
| 63 | + ``` |
| 64 | + kubectl scale deploy mongodb-kubernetes-operator --replicas=1 |
| 65 | + ``` |
| 66 | + |
| 67 | +1. Add your new storage specifications to the `MongoDBCommunity` resource. For example: |
| 68 | + |
| 69 | + ```yaml |
| 70 | + --- |
| 71 | + apiVersion: mongodbcommunity.mongodb.com/v1 |
| 72 | + kind: MongoDBCommunity |
| 73 | + metadata: |
| 74 | + name: example-mongodb |
| 75 | + spec: |
| 76 | + members: 3 |
| 77 | + type: ReplicaSet |
| 78 | + version: "6.0.5" |
| 79 | + statefulSet: |
| 80 | + spec: |
| 81 | + volumeClaimTemplates: |
| 82 | + - metadata: |
| 83 | + name: data-volume |
| 84 | + spec: |
| 85 | + resources: |
| 86 | + requests: |
| 87 | + storage: 100Gi |
| 88 | + ... |
| 89 | + ``` |
| 90 | + |
| 91 | +1. Reapply the `MongoDBCommunity` resource. For example: |
| 92 | + |
| 93 | + ``` |
| 94 | + kubectl apply -f PATH/TO/<MongoDBCommunity-resource>.yaml |
| 95 | + ``` |
| 96 | + |
| 97 | +1. If your storage provisioner doesn't support online expansion, restart the Pods. |
| 98 | + |
| 99 | + ``` |
| 100 | + kubectl rollout restart sts <my-replica-set> |
| 101 | + ``` |
0 commit comments