apiVersion: v1
kind: Service
metadata:
  name: mongo-service
  labels:
    name: mongo
spec:
  type: NodePort
  ports:
    - port: 27017
      targetPort: 27017
      protocol: TCP
  selector:
    role: mongo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo-statefulset
spec:
  selector:
    matchLabels:
      role: mongo
  serviceName: "mongo-service"
  replicas: 1
  template:
    metadata:
      labels:
        role: mongo
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mongo
        image: mongo:4.4.6
        ports:
          - containerPort: 27017
        volumeMounts:
          - name: mongo-persistent-storage
            mountPath: /data/db
        envFrom:
          - configMapRef:
              name: mongo-config
  volumeClaimTemplates:
  - metadata:
      name: mongo-persistent-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 10Gi