apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres-stateful-set
  labels:
    app: hello-world
spec:
  serviceName: postgres-service
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
      tier: postgres
  template:
    metadata:
      labels:
        app: hello-world
        tier: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:14
          ports:
            - containerPort: 5432
          envFrom:
            - secretRef:
                name: hello-world-secret
          volumeMounts:
            - name: postgres-data
              mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
    - metadata:
        name: postgres-data
        labels:
          app: hello-world
          tier: pv-claim
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
