apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:14.2
          imagePullPolicy: IfNotPresent
          ports:
            - name: db
              containerPort: 5432
              protocol: TCP
          env:
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: postgres-credentials
                  key: user
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres-credentials
                  key: password
          envFrom:
            - configMapRef:
                name: postgres-config
          volumeMounts:
            - name: postgres-volume
              mountPath: /var/lib/postgresql/data
            - name: init-scripts-volume
              mountPath: /docker-entrypoint-initdb.d
      initContainers:
        - name: init-scripts
          image: postgres-dbinit:dev
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: init-scripts-volume
              mountPath: /docker-entrypoint-initdb.d
      volumes:
        - name: postgres-volume
          persistentVolumeClaim:
            claimName: postgres-volume-claim
        - name: init-scripts-volume
          emptyDir:
            sizeLimit: 1Gi
