apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  serviceName: postgres
  replicas: 2
  template:
    metadata:
      labels:
        app: postgres
    spec:
      initContainers:
        - name: postgres-volume-init
          image: centos:7.6.1810
          command: ["/bin/bash"]
          args: ["-c", "mkdir /data/data; chown -R 777 /data"]
          volumeMounts:
          - name: postgres-volume
            mountPath: /data
      containers:
      - name: postgres
        image: postgres:11
        ports:
          - containerPort: 5432
        env:
          - name: POSTGRES_PASSWORD
            value: Dummy_123
        volumeMounts:
          - mountPath: "/var/lib/postgresql"
            name: postgres-volume
  volumeClaimTemplates:
  - metadata:
      name: postgres-volume
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "do-block-storage"
      resources:
        requests:
          storage: 1Gi