apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb
  labels:
    app.kubernetes.io/name: mongodb
spec:
  serviceName: mongodb
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb
  replicas: 1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb
    spec:
      containers:
        - name: mongodb
          image: mongo
          args: ["--dbpath","/data/db"]
          livenessProbe:
            exec:
              command:
                - mongo
                - --disableImplicitSessions
                - --eval
                - "db.adminCommand('ping')"
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          readinessProbe:
            exec:
              command:
                - mongo
                - --disableImplicitSessions
                - --eval
                - "db.adminCommand('ping')"
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 6
          ports:
            - name: mongo
              containerPort: 27017
          volumeMounts:
            - name: mongodb-persistent-storage
              mountPath: "/data/db"
      restartPolicy: Always
  volumeClaimTemplates:
    - metadata:
        name: mongodb-persistent-storage
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi