# Create a StorageClass suited for Mongo StatefulSet
# Can be configured with Anti affinity topology key of hostname (default)
#  or across zone.
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: zfspv-mongo
parameters:
  volblocksize: "4k"
  poolname: "zfspv-pool"
  fstype: "xfs"
provisioner: zfs.csi.openebs.io
---
# Headless service for stable DNS entries of StatefulSet members.
apiVersion: v1
kind: Service
metadata:
 name: mongo
 labels:
   name: mongo
spec:
 ports:
 - port: 27017
   targetPort: 27017
 clusterIP: None
 selector:
   role: mongo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
 name: mongo
spec:
 selector:
  matchLabels:
   role: mongo
 serviceName: "mongo"
 replicas: 3
 template:
   metadata:
     labels:
       role: mongo
       environment: test
   spec:
     terminationGracePeriodSeconds: 10
     containers:
       - name: mongo
         image: mongo
         command:
           - mongod
           - "--replSet"
           - rs0
           - "--bind_ip_all"
         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: mongo-persistent-storage
   spec:
     storageClassName: zfspv-mongo
     accessModes:
       - ReadWriteOnce
     resources:
       requests:
         storage: 5Gi
