apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo
  namespace: mongo
spec:
  selector:
    matchLabels:
      app: mongo # has to match .spec.template.metadata.labels
  serviceName: "mongo"
  replicas: 1 # by default is 1
  template:
    metadata:
      labels:
        app: mongo # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mongo
        image: mongo:4.1.5
        env:
        - name: MONGO_INITDB_ROOT_USERNAME
          value: "root"
        - name: MONGO_INITDB_ROOT_PASSWORD
          value: "password"
        ports:
        - containerPort: 27017
          name: tcp
          protocol: TCP
        volumeMounts:
        - name: mongo-pvc
          mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: mongo-pvc
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "local-mongo-storage"
      resources:
        requests:
          storage: 1Gi
