apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  namespace: TARGET_K8S_NAMESPACE
  labels:
    app: postgres
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:13-alpine
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          envFrom:
            - configMapRef:
                name: postgres-config
            - secretRef:
                name: postgres-secret
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
  volumeClaimTemplates:
    - metadata:
        name: postgredb
      spec:
        accessModes:
          - ReadWriteOnce
        # No storageClassName to use the default one.
        # https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-storage
        # storageClassName: "standard"
        resources:
          requests:
            storage: 5Gi