apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres14
  namespace: postgres
spec:
  serviceName: postgres14
  replicas: 1
  selector:
    matchLabels:
      app: postgres14
  template:
    metadata:
      labels:
        app: postgres14
    spec:
      containers:

      - name: postgres14
        image: postgres:14
#        command: ["sh"]
#        args: ["-c", "while true; do echo $(date -u) >> /tmp/run.log; sleep 5; done"]
        ports:
          - containerPort: 5432
        env:
        - name: POSTGRES_DB
          value: postgres
        - name: POSTGRES_USER
          value: postgres
        - name: POSTGRES_PASSWORD
          value: Postgres14
        volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: postgres
      volumes:
      - name: postgres
        persistentVolumeClaim:
          claimName: postgres14-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: postgres14
  namespace: postgres
  labels:
    name: postgres14
spec:
  type: ClusterIP
  ports:
    - port: 5432
      name: postgres
  selector:
    app: postgres14
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgres14-pv
spec:
  storageClassName: ""
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    server: 192.168.2.110
    path: /mnt/nfs_share/postgres14prod
    readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres14-pvc
  namespace: postgres
spec:
  storageClassName: ""
  volumeName: postgres14-pv
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 2Gi
