apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: pg
  labels:
    app: pg
spec:
  selector:
    matchLabels:
      app: pg
  serviceName: postgres
  #minReadySeconds: 10 # Kubernetes v1.23 [beta]
  replicas: 1
  revisionHistoryLimit: 2
  template:
    metadata:
      labels:
        app: pg
    spec:
      terminationGracePeriodSeconds: 20
      containers:
        - name: pg #DNS_LABLE
          image: postgres:14.1-alpine3.15
          imagePullPolicy: IfNotPresent
          ports:
            - name: db
              containerPort: 5432
          resources:
            requests:
              cpu: 100m # one hundred millicores or millicpu
              memory: 100Mi
            limits:
              cpu: 300m
              memory: 250Mi
          envFrom:
            - configMapRef:
                name: pg-config
          volumeMounts:
            - name: pg-data
              mountPath: /data
          livenessProbe:
            # проверить работоспособность этого зонда не знаю как
            exec:
              command:
                - "/bin/sh"
                - "-c"
                - | 
                - psql -U $POSTGRES_USER -d $POSTGRES_DB -c 'SELECT 1'
            initialDelaySeconds: 20
            timeoutSeconds: 3
            failureThreshold: 3
            periodSeconds: 5
            successThreshold: 1

  volumeClaimTemplates:
    - metadata:
        name: pg-data
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 50Mi