apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  serviceName: "postgres"
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: postgres
        image: gcr.io/ucdlib-pubreg/krm-postgis:main
        env:
        - name: PGDATA
          value: "/var/lib/postgresql/data/pgdata"
        ports:
        - containerPort: 27017
        volumeMounts:
        - name: postgres-persistent-storage
          mountPath: /var/lib/postgresql/data
        resources:
          limits:
            memory: "2Gi"
            cpu: "2"
          requests:
            memory: "64Mi"
            cpu: "100m"
      nodeSelector:
        intendedfor: krm-services
  # TODO: look to switch to: 
  # https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/preexisting-pd
  volumeClaimTemplates:
  - metadata:
      name: postgres-persistent-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 25Gi
