IOMesh for MongoDB
Setup k8s Cluster Storage
Create a file named
iomesh-mongodb-sc.yaml
with the following contents:kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: iomesh-mongodb-sc provisioner: com.iomesh.csi-driver # driver.name in values.yaml when install IOMesh reclaimPolicy: Retain allowVolumeExpansion: true parameters: csi.storage.k8s.io/fstype: "ext4" replicaFactor: "2" thinProvision: "true"
Apply the yaml config:
kubectl apply -f iomesh-mongodb-sc.yaml
Deploy MongoDB
Create a headless Service for MongoDB
Create a Service used for DNS lookups between MongoDB Pods and the clients within your cluster
apiVersion: v1 kind: Service metadata: name: mongo labels: name: mongo spec: ports: - port: 27017 targetPort: 27017 clusterIP: None selector: role: mongo
Apply the yaml config:
kubectl apply -f mongodb-service.yaml
Create MongoDB cluster using pv provided for IOMesh Storage
Use StatefulSet to create a MongoDB cluster
apiVersion: apps/v1beta1 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 - "--smallfiles" - "--noprealloc" ports: - containerPort: 27017 volumeMounts: - name: mongo-persistent-storage 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 # storageClass created above resources: requests: storage: 10Gi
Apply the yaml config:
kubectl apply -f mongodb-statefulset.yaml
IOMesh Storage will create Persistent Volumes for each MongoDB pod. These volumes use ext4 file system with a replica factor of 2 and thin provision.
Operate MongoDB Data
Users can use the features provided by IOMesh storage to perform such operations as expansion/snapshot/rollback/clone of the Persistent Volumes where MongoDB data are located, see the reference for details application-operations