Docs Menu
Docs Home
/
MongoDB Enterprise Kubernetes Operator
/ /

Resize Storage for One Database Resource

On this page

  • Prerequisites
  • Procedure

Make sure the StorageClass and volume plugin provider that the Persistent Volumes use supports resize:

kubectl patch storageclass/<my-storageclass> --type='json' \
-p='[{"op": "add", "path": "/allowVolumeExpansion", "value": true }]'

If you don't have a StorageClass that supports resizing, ask your Kubernetes administrator to help.

1

Use an existing database resource or create a new one with persistent storage. Wait until the persistent volume gets to the Running state.

Example

A database resource with persistent storage would include:

1apiVersion: mongodb.com/v1
2kind: MongoDB
3metadata:
4 name: <my-replica-set>
5spec:
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
  1. Start mongo in the Kubernetes cluster.

    $kubectl exec -it <my-replica-set>-0 \
    /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.4.0/bin/mongo
  2. Insert data into the test database.

    <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

Invoke the following commands for the entire replica set:

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"}}}}'

Wait until each Persistent Volume Claim gets to the following condition:

- 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

Note

This step removes the StatefulSet only. The pods remain unchanged and running.

Delete a StatefulSet resource.

kubectl delete sts --cascade=false <my-replica-set>
5
  1. Update the disk size. Open your preferred text editor and make changes similar to this example:

    Example

    To update the disk size of the replica set to 2 GB, change the storage value in database resource specification:

    1apiVersion: mongodb.com/v1
    2kind: MongoDB
    3metadata:
    4 name: <my-replica-set>
    5spec:
    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"
  2. Recreate a StatefulSet resource with the new volume size.

    kubectl apply -f my-replica-set-vol.yaml
  3. Wait until this StatefulSet achieves the Running state.

6

Invoke the following command:

kubectl rollout restart sts <my-replica-set>

The new pods mount the resized volume.

7

If the Persistent Volumes were reused, the data that you inserted in Step 2 can be found on the databases stored in Persistent Volumes:

$ kubectl exec -it <my-replica-set>-1 \
/var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.4.0/bin/mongo
<my-replica-set>:PRIMARY> use test
switched to db test
<my-replica-set>:PRIMARY> db.tmp.count()
1
← Scale a Deployment