IOMesh for MongoDB
Prerequisite
Verify the IOMesh cluster is already deployed.
Procedure
NOTE: The following example does not apply to a
AArch64Kubernetes cluster.
Create a YAML config
iomesh-mongodb-sc.yamlwith the following content. You may also use the default StorageClassiomesh-csi-driver. See more details in Create StorageClass.kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: iomesh-mongodb-sc provisioner: com.iomesh.csi-driver # The driver name in `iomesh.yaml`. reclaimPolicy: Retain allowVolumeExpansion: true parameters: csi.storage.k8s.io/fstype: "ext4" replicaFactor: "2" thinProvision: "true"Apply the YAML config to create the StorageClass.
kubectl apply -f iomesh-mongodb-sc.yamlCreate a YAML config
mongodb-service.yamlwith the following content. This file defines the headless service, which is used for DNS lookups between MongoDB pods and clients within your cluster.apiVersion: v1 kind: Service metadata: name: mongo labels: name: mongo spec: ports: - port: 27017 targetPort: 27017 clusterIP: None selector: role: mongoApply the YAML config to create the headless service.
kubectl apply -f mongodb-service.yamlCreate a StatefulSet
mongodb-statefulset.yamlwith the following content. In the fieldstorageClassName, type the StorageClass you specify in Step 1.apiVersion: apps/v1 kind: StatefulSet metadata: name: mongo spec: selector: matchLabels: role: mongo environment: test serviceName: "mongo" replicas: 3 template: metadata: labels: role: mongo environment: test spec: terminationGracePeriodSeconds: 10 containers: - name: mongo image: mongo command: - mongod - "--replSet" - rs0 ports: - containerPort: 27017 volumeMounts: - name: mongodb-data mountPath: /data/db - name: mongo-sidecar image: cvallance/mongo-k8s-sidecar env: - name: MONGO_SIDECAR_POD_LABELS value: "role=mongo,environment=test" volumeClaimTemplates: - metadata: name: mongodb-data spec: accessModes: [ "ReadWriteOnce" ] storageClassName: iomesh-mongodb-sc # The StorageClass in Step 1. resources: requests: storage: 10GiApply the YAML config to deploy MongoDB.
kubectl apply -f mongodb-statefulset.yamlAfter completion, IOMesh will create a PV for the MongoDB pod with configurations such as filesystem type and replication factor specified in the StorageClass.
Once done, you can expand, snapshot, or clone persistent volumes where MongoDB data are located. For details, refer to Volume Operations and VolumeSnapshot Operations.