apiVersion: apps/v1
kind: Deployment
metadata:
  name: db
spec:
  selector:
    matchLabels:
      app: db
  template:
    metadata:
      labels:
        app: db
    spec:
      containers:
      - name: db
        image: mongo
        imagePullPolicy: Always
        ports:
        - containerPort: 27017
        env:
        - name: MONGO_INITDB_DATABASE
          valueFrom:
            configMapKeyRef:
              name: dbconfig
              key: DB_NAME
        volumeMounts:
        - mountPath: /var/lib/mongodb/data
          name: db-volume-mount
          subPath: db
      volumes:
      - name: db-volume-mount
        persistentVolumeClaim:
          claimName: db