apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres-statefulset-v3
spec:
  serviceName: database
  selector:
    matchLabels:
      name: postgres
  template:
    metadata:
      labels:
        name: postgres
    spec:
      containers:
        - name: postgres-container
          image: postgres:11
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              value: 'database'
            - name: POSTGRES_USER
              value: 'root'
            - name: POSTGRES_PASSWORD
              value: 'root'
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgres-volume
      volumes:
        - name: postgres-volume
          persistentVolumeClaim:
            claimName: postgres-pvc
