apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgresql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgresql
  template:
    metadata:
      labels:
        app: postgresql
    spec:
      containers:
        - name: postgresql
          image: 'docker.io/bitnami/postgresql:12.2.0'
          ports:
            - name: tcp-postgresql
              containerPort: 5432
              protocol: TCP
          env:
            - name: POSTGRESQL_PORT_NUMBER
              value: '5432'
            - name: POSTGRESQL_VOLUME_DIR
              value: /bitnami/postgresql
            - name: PGDATA
              value: /bitnami/postgresql/data
            - name: POSTGRES_USER
              value: postgres
              #dont even try this in production
            - name: POSTGRES_PASSWORD
              value: postgres
            - name: POSTGRES_DB
              value: kubernetes
            - name: DISABLE_WELCOME_MESSAGE
              value: 'true'
            - name: POSTGRESQL_ENABLE_LDAP
              value: 'no'
          resources:
            requests:
              cpu: 250m
              memory: 256Mi
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - '-c'
                - >-
                  exec pg_isready -U "postgres" -d "kubernetes" -h 127.0.0.1 -p
                  5432
            initialDelaySeconds: 30
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 6
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - '-c'
                - '-e'
                - >
                  exec pg_isready -U "postgres" -d "kubernetes" -h 127.0.0.1 -p
                  5432

                  [ -f /opt/bitnami/postgresql/tmp/.initialized ] || [ -f
                  /bitnami/postgresql/.initialized ]
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 6
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
# we run database without any persistent data volume - not a good idea, but sufficient for demo
