apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  serviceName: postgres
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:12
          imagePullPolicy: Always
          securityContext:
            readOnlyRootFilesystem: true
          envFrom:
            - configMapRef:
                name: postgres-config
            - secretRef:
                name: postgres-secrets
          ports:
            - name: postgres
              containerPort: 5432
          volumeMounts:
            - name: data
              mountPath: /var/lib/postgresql/data
            - name: run
              mountPath: /var/run
          resources:
            requests:
              cpu: 100m
              memory: 500Mi
            limits:
              cpu: 300m
              memory: 700Mi
          livenessProbe:
            exec:
              command: ["pg_isready", "-U", "postgres", "-h", "localhost"]
          readinessProbe:
            exec:
              command: ["pg_isready", "-U", "postgres", "-h", "localhost"]
      volumes:
        - name: run
          emptyDir: {}

  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 5Gi
