apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mom-database
  labels:
    app: mom-database
spec:
  serviceName: mom-database
  replicas: 1
  selector:
    matchLabels:
      app: mom-database
  template:
    metadata:
      labels:
        app: mom-database
    spec:
      containers:
      - name: postgres
        image: postgres:15
        ports:
        - containerPort: 5432
        env:
        - name: POSTGRES_DB
          value: mom
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: mom-db-credentials
              key: username
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mom-db-credentials
              key: password
        volumeMounts:
        - name: postgres-storage
          mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
  - metadata:
      name: postgres-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
  name: mom-database
spec:
  selector:
    app: mom-database
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432 