apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: postgres
  name: postgres
  namespace: todo-app-ns
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:10.1
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: todoapp
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: todoapp-postgress-secret
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: todoapp-postgress-secret
                  key: POSTGRES_PASSWORD              
          volumeMounts:
            - mountPath: "/var/lib/postgresql/data"
              name: "postgres-volume"
              subPath: postgres
      volumes:
        - name: postgres-volume
          persistentVolumeClaim:
            claimName: postgres-pvc
