apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo-db-statefulset
  labels:
    mongoDB-replica: "true"
    mongoDB-secured: "true"
    mongoDB-sharding: "false"
  annotations: 
    author: JMCF
  namespace: sec-datastores
spec: 
  selector: 
    matchLabels:
      app: mongoDB-replica
  serviceName: mongo-db-replica
  replicas: 3
  template:
    metadata: 
      labels: 
        app: mongoDB-replica
    spec: 
      terminationGracePeriodSeconds: 10
      volumes: 
        - name: secret-volume
          secret:
            secretName: mongo-secret
      containers: 
        - name: mongo-db
          image: mongo:4.2.6
          ports: 
            - containerPort: 27017
              protocol: TCP
          volumeMounts: 
            - mountPath: /data/db
              name: mongo-volume-for-replica
            - mountPath: /var/secrets
              name: secret-volume
          args: 
            - --replSet
            - $(REPLICA_SET_NAME)
            - --auth
            - --keyFile
            - /var/secrets/replica.key
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
          envFrom: 
            - configMapRef:
                name: mongo-config
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              valueFrom:
                secretKeyRef:
                  name: mongo-secret
                  key: root-user
            - name: MONGO_INITDB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongo-secret
                  key: root-pwd
  volumeClaimTemplates: 
    - metadata: 
        name: mongo-volume-for-replica
      spec: 
        accessModes: 
          - ReadWriteOnce
        resources: 
          requests: 
            storage: 100Mi
