apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  serviceName: postgres-service
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  volumeClaimTemplates:
  - metadata:
      name: db-storage
    spec:
      storageClassName: standard
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:alpine
        env:
          - name: POSTGRES_DB
            value: heroes
          - name: POSTGRES_PASSWORD
            value: mysecretpassword
        ports:
        - containerPort: 5432
          name: postgres
        volumeMounts:
        - name: db-storage
          mountPath: /var/lib/postgresql/data