apiVersion: apps/v1
kind: Deployment
metadata:
  name: mom-database
  labels:
    app: mom-database
spec:
  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
      volumes:
      - name: postgres-storage
        persistentVolumeClaim:
          claimName: mom-database-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: mom-database
spec:
  selector:
    app: mom-database
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mom-database-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi 