# apiVersion: v1
# kind: PersistentVolume
# metadata:
#   name: postgresdb-pv
# spec:
#   accessModes:
#     - ReadWriteMany
#   capacity:
#     storage: 10Gi
#   persistentVolumeReclaimPolicy: Retain
#   storageClassName: standard
#   gcePersistentDisk:
#     fsType: ext4
#     pdName: apache-fineract-pd

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgresdb-pvc
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

---

apiVersion: v1
kind: Service
metadata:
  name: postgresdb-cluster
  namespace: default
spec:
  selector:
    app: postgresdb
  ports:
  - port: 5432
    targetPort: 5432
  type: LoadBalancer

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgresdb-cluster
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgresdb
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: postgresdb
    spec:
      containers:
        - image: postgres:9.5
          imagePullPolicy: IfNotPresent
          name: postgres
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_USER
              value: postgres
            - name: POSTGRES_PASSWORD
              value: postgres
          livenessProbe:
            exec:
              command:
                - psql
                - --help
            initialDelaySeconds: 10
            timeoutSeconds: 1
            periodSeconds: 10
            failureThreshold: 3
          volumeMounts:
            - mountPath: /var/lib/postgresql
              name: postgresdb-storage
      volumes:
        - name: postgresdb-storage
          persistentVolumeClaim:
            claimName: postgresdb-pvc
