apiVersion: apps/v1
kind: Deployment
metadata:
  name: wintercms-postgres
  namespace: wintercms
  labels:
    app: wintercms-app
    tier: db
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: wintercms-app
      tier: db
  template:
    metadata:
      labels:
        app: wintercms-app
        tier: db
    spec:
      containers:
        - name: wintercms-postgres
          image: postgres:10.3-alpine
          imagePullPolicy: "IfNotPresent"
          env:
          - name: POSTGRES_DB
            valueFrom:
              secretKeyRef:
                name: wintercms-postgres-secret
                key: POSTGRES_DB
          - name: POSTGRES_USER
            valueFrom:
              secretKeyRef:
                name: wintercms-postgres-secret
                key: POSTGRES_USER
          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                name: wintercms-postgres-secret
                key: POSTGRES_PASSWORD
          ports:
          - containerPort: 5432
          readinessProbe:
            exec:
              command:
                - sh
                - -c
                - su - postgres -c "pg_isready --host=$POD_IP"
            initialDelaySeconds: 15
            timeoutSeconds: 2
          resources: {}
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
              subPath: postgres
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: wintercms-postgres-data
