apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: geocrop-db-pvc
  namespace: geocrop
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: geocrop-db
  namespace: geocrop
spec:
  replicas: 1
  selector:
    matchLabels:
      app: geocrop-db
  template:
    metadata:
      labels:
        app: geocrop-db
    spec:
      containers:
      - name: postgis
        image: postgis/postgis:15-3.4
        ports:
        - containerPort: 5432
        env:
        - name: POSTGRES_DB
          value: geocrop_gis
        - name: POSTGRES_USER
          value: postgres
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: geocrop-db-secret
              key: password
        resources:
          limits:
            memory: "512Mi" # Lightweight DB limit
          requests:
            memory: "256Mi"
        volumeMounts:
        - name: db-data
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: db-data
        persistentVolumeClaim:
          claimName: geocrop-db-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: geocrop-db
  namespace: geocrop
spec:
  ports:
  - port: 5433
    targetPort: 5432
  selector:
    app: geocrop-db
