|
| 1 | +--- |
| 2 | +stepnum: 1 |
| 3 | +level: 4 |
| 4 | +ref: select-resource |
| 5 | +title: Create or identify a persistent |k8s-custom-resource|. |
| 6 | +content: | |
| 7 | +
|
| 8 | + Use an existing database resource or create a new one with persistent |
| 9 | + storage. Wait until the peristent volume gets to the ``Running`` |
| 10 | + state. |
| 11 | +
|
| 12 | + .. example:: |
| 13 | +
|
| 14 | + A database resource with persistent storage would include: |
| 15 | +
|
| 16 | + .. code-block:: yaml |
| 17 | + :linenos: |
| 18 | + :emphasize-lines: 13-15 |
| 19 | +
|
| 20 | + apiVersion: mongodb.com/v1 |
| 21 | + kind: MongoDB |
| 22 | + metadata: |
| 23 | + name: <my-replica-set> |
| 24 | + spec: |
| 25 | + members: 3 |
| 26 | + version: 4.0.4 |
| 27 | + project: my-project |
| 28 | + credentials: my-credentials |
| 29 | + type: ReplicaSet |
| 30 | + podSpec: |
| 31 | + memory: 300M |
| 32 | + persistence: |
| 33 | + single: |
| 34 | + storage: 1G |
| 35 | +
|
| 36 | +--- |
| 37 | +stepnum: 2 |
| 38 | +level: 4 |
| 39 | +ref: insert-data |
| 40 | +title: Insert data to the database that the resource serves. |
| 41 | +content: | |
| 42 | +
|
| 43 | + a. Start |mongo| in the |k8s| cluster. |
| 44 | +
|
| 45 | + .. code-block:: sh |
| 46 | +
|
| 47 | + $kubectl exec -it <my-replica-set>-0 \ |
| 48 | + /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.0.4/bin/mongo |
| 49 | +
|
| 50 | + b. Insert data into the ``test`` database. |
| 51 | +
|
| 52 | + .. code-block:: javascript |
| 53 | + :copyable: false |
| 54 | +
|
| 55 | + <my-replica-set>:PRIMARY> use test |
| 56 | +
|
| 57 | + switched to db test |
| 58 | +
|
| 59 | + <my-replica-set>:PRIMARY> db.tmp.insert({"foo":"bar"}) |
| 60 | +
|
| 61 | + WriteResult({ "nInserted" : 1 }) |
| 62 | +
|
| 63 | +--- |
| 64 | +stepnum: 3 |
| 65 | +level: 4 |
| 66 | +ref: patch-pv |
| 67 | +title: Patch each persistence volume. |
| 68 | +content: | |
| 69 | +
|
| 70 | + Invoke the following commands for the entire replica set: |
| 71 | +
|
| 72 | + .. code-block:: sh |
| 73 | +
|
| 74 | + kubectl patch pvc/"data-<my-replica-set>-0" -p='{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}' |
| 75 | + kubectl patch pvc/"data-<my-replica-set>-1" -p='{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}' |
| 76 | + kubectl patch pvc/"data-<my-replica-set>-2" -p='{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}' |
| 77 | +
|
| 78 | + Wait until each |k8s-pvc| gets to the following condition: |
| 79 | +
|
| 80 | + .. code-block:: yaml |
| 81 | +
|
| 82 | + - lastProbeTime: null |
| 83 | + lastTransitionTime: "2019-08-01T12:11:39Z" |
| 84 | + message: Waiting for user to (re-)start a pod to finish file |
| 85 | + system resize of volume on node. |
| 86 | + status: "True" |
| 87 | + type: FileSystemResizePending |
| 88 | +--- |
| 89 | +stepnum: 4 |
| 90 | +level: 4 |
| 91 | +ref: update-crd |
| 92 | +title: Update the database resource with a new storage value. |
| 93 | +content: | |
| 94 | +
|
| 95 | + .. example:: |
| 96 | +
|
| 97 | + To update the disk size of the replica set to 2 GB, change the |
| 98 | + ``storage`` value in database resource specification: |
| 99 | +
|
| 100 | + .. code-block:: yaml |
| 101 | + :linenos: |
| 102 | + :emphasize-lines: 15 |
| 103 | +
|
| 104 | + apiVersion: mongodb.com/v1 |
| 105 | + kind: MongoDB |
| 106 | + metadata: |
| 107 | + name: <my-replica-set> |
| 108 | + spec: |
| 109 | + members: 3 |
| 110 | + version: 4.0.4 |
| 111 | + project: my-project |
| 112 | + credentials: my-credentials |
| 113 | + type: ReplicaSet |
| 114 | + podSpec: |
| 115 | + memory: 300M |
| 116 | + persistence: |
| 117 | + single: |
| 118 | + storage: 2G |
| 119 | +
|
| 120 | +--- |
| 121 | +stepnum: 5 |
| 122 | +level: 4 |
| 123 | +ref: recreate-statefulsets |
| 124 | +title: Recreate the StatefulSets. |
| 125 | +content: | |
| 126 | +
|
| 127 | + a. Delete a |k8s-statefulset| resource. |
| 128 | +
|
| 129 | + .. code-block:: sh |
| 130 | +
|
| 131 | + kubectl delete sts --cascade=false <my-replica-set> |
| 132 | +
|
| 133 | + b. Recreate a |k8s-statefulset| resource with the new volume size. |
| 134 | +
|
| 135 | + |k8s-op-short| deletes the |k8s-statefulset|, but the pods remain |
| 136 | + unchanged and running. |
| 137 | +
|
| 138 | + .. code-block:: sh |
| 139 | +
|
| 140 | + kubectl apply -f my-replica-set-vol.yaml |
| 141 | +
|
| 142 | + c. Wait until this StatefulSet achieves the ``Running`` state. |
| 143 | +
|
| 144 | +--- |
| 145 | +stepnum: 6 |
| 146 | +level: 4 |
| 147 | +ref: update-pods |
| 148 | +title: Update the pods in a rolling fashion. |
| 149 | +content: | |
| 150 | +
|
| 151 | + Invoke the following command: |
| 152 | +
|
| 153 | + .. code-block:: sh |
| 154 | +
|
| 155 | + kubectl rollout restart sts <my-replica-set> |
| 156 | +--- |
| 157 | +stepnum: 7 |
| 158 | +level: 4 |
| 159 | +ref: validate-pv-change |
| 160 | +title: Validate data exists on the updated |k8s-pvc|. |
| 161 | +content: | |
| 162 | +
|
| 163 | + If the |k8s-pvs| were reused, the data that you inserted in **Step |
| 164 | + 2** can be found on the databases stored in |k8s-pvs|: |
| 165 | +
|
| 166 | + .. code-block:: sh |
| 167 | +
|
| 168 | + $ kubectl exec -it <my-replica-set>-1 \ |
| 169 | + /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.0.4/bin/mongo |
| 170 | +
|
| 171 | + .. code-block:: javascript |
| 172 | + :copyable: false |
| 173 | +
|
| 174 | + <my-replica-set>:PRIMARY> use test |
| 175 | + switched to db test |
| 176 | +
|
| 177 | + <my-replica-set>:PRIMARY> db.tmp.count() |
| 178 | + 1 |
0 commit comments