apiVersion: apps/v1
kind: Deployment

metadata:
  name: postgres-deployment

spec:
  replicas: 1

  selector:
    matchLabels:
      server: db

  template:
    metadata:
      labels:
        server: db

    spec:
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: postgres-volume-claim
      containers:
        - name: postgres
          image: postgres
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: postgres-storage
              mountPath: /var/lib/postgresql/data
          env:
            - name: POSTGRES_USER
              value: "tiolktrack"
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: tiolktrack-secret
                  key: DB_PASSWORD
            - name: PGDATA
              value: /var/lib/postgresql/data/pgdata