apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mongodb
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9216"
    spec:
      containers:
      - name: mongodb
        image: yurak/mongodb:latest
        imagePullPolicy: Always
        ports:
        - name: mongodb
          containerPort: 27017
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          valueFrom:
            configMapKeyRef:
              name: mongodb-configmap
              key: mongodb-root-user
        - name: MONGO_INITDB_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongodb-root-password
        - name: TZ
          valueFrom:
            configMapKeyRef:
              name: mongodb-configmap
              key: tz
        - name: MONGO_INITDB_DATABASE
          valueFrom:
            configMapKeyRef:
              name: mongodb-configmap
              key: mongodb-initdb
        volumeMounts:
        - name: mongodb-persistent-storage
          mountPath: /data/db
      - name: mongodb-exporter
        image: ssheehy/mongodb-exporter:0.10.0
        ports:
        - containerPort: 9216
        env:
        - name: MONGODB_URI
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: mongodb-exporter-uri
      volumes:
      - name: mongodb-persistent-storage
        persistentVolumeClaim:
          claimName: mongodb-pvc
