apiVersion: v1
kind: Service
metadata:
  name: orcheo-postgres
spec:
  selector:
    app: orcheo-postgres
  ports:
    - name: postgres
      port: 5432
      targetPort: 5432
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: orcheo-postgres
spec:
  serviceName: orcheo-postgres
  replicas: 1
  selector:
    matchLabels:
      app: orcheo-postgres
  template:
    metadata:
      labels:
        app: orcheo-postgres
    spec:
      containers:
        - name: postgres
          image: postgres:16
          ports:
            - containerPort: 5432
              name: postgres
          env:
            - name: POSTGRES_DB
              value: orcheo
            - name: POSTGRES_USER
              value: orcheo
            - name: POSTGRES_PASSWORD
              value: orcheo
          readinessProbe:
            exec:
              command: ["pg_isready", "-U", "orcheo", "-d", "orcheo"]
            initialDelaySeconds: 10
            periodSeconds: 10
          livenessProbe:
            exec:
              command: ["pg_isready", "-U", "orcheo", "-d", "orcheo"]
            initialDelaySeconds: 20
            periodSeconds: 20
          volumeMounts:
            - name: pgdata
              mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
    - metadata:
        name: pgdata
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi
