apiVersion: apps/v1
kind: Deployment
metadata:
  name: scrumlr-database
spec:
  replicas: 1
  selector:
    matchLabels:
      app: scrumlr-database
  template:
    metadata:
      labels: 
        app: scrumlr-database
    spec:
      containers:
        - name: scrumlr-database
          image: mongo
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 27017
          livenessProbe:
            exec:
              command:
                - mongo
                - --eval
                - db.adminCommand('ping') 
            initialDelaySeconds: 30
            periodSeconds: 5
            timeoutSeconds: 10
          readinessProbe:
            exec:
              command:
                - bash 
                - -ec
                - | 
                  mongo --eval 'db.hello().isWritablePrimary || db.hello().secondary' | grep -q 'true'
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 10
      restartPolicy: Always
      volumes:
      - name: database-persistent-storage
        persistentVolumeClaim:
          claimName: database-pv-claim