apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: calminer-db
spec:
  serviceName: calminer-db
  replicas: 1
  selector:
    matchLabels:
      app: calminer-db
  template:
    metadata:
      labels:
        app: calminer-db
    spec:
      containers:
        - name: postgres
          image: postgres:17
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_USER
              value: "calminer"
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: calminer-secrets
                  key: DATABASE_PASSWORD
            - name: POSTGRES_DB
              value: "calminer_db"
          resources:
            requests:
              memory: "256Mi"
              cpu: "250m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          volumeMounts:
            - name: postgres-storage
              mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
    - metadata:
        name: postgres-storage
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi
