apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  namespace: postgres
spec:
  selector:
    matchLabels:
      app: postgres # has to match .spec.template.metadata.labels
  serviceName: "postgres"
  replicas: 1 # by default is 1
  template:
    metadata:
      labels:
        app: postgres # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: postgres
        image: postgres:12.4-alpine
        env:
        - name: POSTGRES_USER
          value: "postgres"
        - name: POSTGRES_PASSWORD
          value: "password"
        - name: PGDATA
          value: "/var/lib/postgresql/data"
        ports:
        - containerPort: 5432
          name: tcp
          protocol: TCP
        volumeMounts:
        - name: postgres-pvc
          mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
  - metadata:
      name: postgres-pvc
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "local-postgres-storage"
      resources:
        requests:
          storage: 1Gi
