apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: firefly-postgres-pvc
  namespace: firefly
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
  storageClassName: managed-premium
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: firefly-postgres
  namespace: firefly
spec:
  serviceName: firefly-postgres
  replicas: 1
  selector:
    matchLabels:
      app: firefly-postgres
  template:
    metadata:
      labels:
        app: firefly-postgres
    spec:
      containers:
      - name: postgres
        image: postgres:15-alpine
        env:
        - name: POSTGRES_USER
          value: firefly
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: firefly-secrets
              key: db-password
        - name: POSTGRES_DB
          value: firefly
        ports:
        - containerPort: 5432
          name: postgres
        volumeMounts:
        - name: postgres-data
          mountPath: /var/lib/postgresql/data
        resources:
          requests:
            cpu: "500m"
            memory: "1Gi"
          limits:
            cpu: "2"
            memory: "4Gi"
        livenessProbe:
          exec:
            command:
            - pg_isready
            - -U
            - firefly
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          exec:
            command:
            - pg_isready
            - -U
            - firefly
          initialDelaySeconds: 10
          periodSeconds: 5
  volumeClaimTemplates:
  - metadata:
      name: postgres-data
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 50Gi
      storageClassName: managed-premium
---
apiVersion: v1
kind: Service
metadata:
  name: firefly-postgres
  namespace: firefly
spec:
  selector:
    app: firefly-postgres
  ports:
  - port: 5432
    targetPort: 5432
    name: postgres
  clusterIP: None

