---
apiVersion: v1
kind: Secret
metadata:
  name: postgres-secret
type: kubernetes.io/basic-auth
stringData:
  username: reviewer-recommender
  password: ml4dawin

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pvc
spec:
  storageClassName: local-path
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:13-alpine
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: postgres-pv
              mountPath: /var/lib/postgresql/data
              subPath: postgres
          resources:
            limits:
              memory: 256Mi
              cpu: 250m
          env:
            - name: POSTGRES_DB
              value: reviewer-recommender
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: username
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres-secret
                  key: password
      volumes:
        - name: postgres-pv
          persistentVolumeClaim:
            claimName: postgres-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  type: ClusterIP
  selector:
    app: postgres
  ports:
    - port: 5432
      targetPort: 5432
