apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb
  namespace: cap
spec:
  serviceName: mongodb
  selector:
    matchLabels:
      app: mongodb
  replicas: 3
  template:
    metadata:
      labels:
        app: mongodb
    
    spec:
      securityContext:
        fsGroup: 1001
      containers:
        - name: mongodb
          image: bitnami/mongodb
          imagePullPolicy: IfNotPresent
          env:
           
            - name: MONGODB_DISABLE_SYSTEM_LOG
              value: "false"
            - name: MONGODB_SYSTEM_LOG_VERBOSITY
              value: "1"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MONGODB_REPLICA_SET_NAME
              value: "replicaset"
            - name: MONGODB_INITIAL_PRIMARY_HOST
              value: "mongodb-0.mongodb.cicd.svc.cluster.local"
            - name: MONGODB_ADVERTISED_HOSTNAME
              value: "$(POD_NAME).mongodb.cicd.svc.cluster.local"
            - name: ALLOW_EMPTY_PASSWORD
              value: "yes"
          command:
            - /scripts/script.sh
          securityContext:
            runAsUser: 1001
          volumeMounts:
            - name: config
              mountPath: /scripts
            - name: data
              mountPath: /bitnami/mongodb
              
      volumes:
        - name: config
          configMap:
            name: mongo-config
            defaultMode: 0755
            items:
              - key: script.sh
                path: script.sh
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ReadWriteOnce]
        resources:
          requests:
            storage: 500Mi
        storageClassName: fast

