---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgresql
spec:
  serviceName: "sonar-psql"
  selector:
    matchLabels:
      run: sonar-psql
  template:
    metadata:
      labels:
        run: sonar-psql
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: role
                operator: NotIn
                values:
                - "cloud"
      containers:
      - name: postgresql
        image: postgres:14.1
        volumeMounts:
          - name: snr-psql-data
            mountPath: /var/lib/postgresql/data
            subPath: postgres
        env:
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: sonar-postgres
              key: pgpassword
        ports:
        - containerPort: 5432
          name: psql
      volumes:
      - name: snr-psql-data
        persistentVolumeClaim:
          claimName: snr-psql-data-postgresql-0
  volumeClaimTemplates:
  - metadata:
      name: snr-psql-data
    spec:
      storageClassName: "nfs-client"
      accessModes: [ "ReadWriteMany" ]
      resources:
        requests:
          storage: 10Gi
