apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: mongo
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        component: mongo
    spec:
      volumes:
        - name: mongo-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
      containers:
        - image: mongo
          name: mongo
          ports:
            - containerPort: 27017
          volumeMounts:
            - name: mongo-storage
              mountPath: /data/db
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              valueFrom:
                secretKeyRef:
                  name: mysecret
                  key: MONGO_USERNAME
            - name: MONGO_INITDB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysecret
                  key: MONGO_PASSWORD
