Postgres Operator

Deploy the operator following the installation guide here: https://github.com/zalando/postgres-operator/blob/v1.8.2/docs/quickstart.md#deployment-options

Once the operator has been deployed, can a Postgres cluster be defined with the help of its CustomResourceDefinition

apiVersion: "acid.zalan.do/v1"
kind: postgresql
metadata:
  name: test-db
spec:
  teamId: "test"
  volume:
    size: 1Gi
  numberOfInstances: 3
  users:
    test_user:  # database owner
      - superuser
      - createdb
  databases:
    test: test_user  # dbname: owner
  postgresql:
    version: "14"
    parameters:
      huge_pages: "off"
  additionalVolumes:
  - mountPath: /usr/share/postgresql/9.6/postgresql.conf.sample
    name: pg-init-config-9
    subPath: postgresql.conf.sample
    volumeSource:
      configMap:
        name: pg-init-config
  - mountPath: /usr/share/postgresql/10/postgresql.conf.sample
    name: pg-init-config-10
    subPath: postgresql.conf.sample
    volumeSource:
      configMap:
        name: pg-init-config
  - mountPath: /usr/share/postgresql/11/postgresql.conf.sample
    name: pg-init-config-11
    subPath: postgresql.conf.sample
    volumeSource:
      configMap:
        name: pg-init-config
  - mountPath: /usr/share/postgresql/12/postgresql.conf.sample
    name: pg-init-config-12
    subPath: postgresql.conf.sample
    volumeSource:
      configMap:
        name: pg-init-config
  - mountPath: /usr/share/postgresql/13/postgresql.conf.sample
    name: pg-init-config-13
    subPath: postgresql.conf.sample
    volumeSource:
      configMap:
        name: pg-init-config
  - mountPath: /usr/share/postgresql/14/postgresql.conf.sample
    name: pg-init-config-14
    subPath: postgresql.conf.sample
    volumeSource:
      configMap:
        name: pg-init-config
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: pg-init-config
data:
  postgresql.conf.sample: "huge_pages = off"

Mount database secrets in deployment (Password and Username)

We recommend creating the Postgres cluster in the same namespace as the application that requires the database to enable the ability to mount secrets in the deployment.

- name: USER
  valueFrom:
    secretKeyRef:
      key: username
      name: test-user.test-db.credentials.postgresql.acid.zalan.do
- name: PASSWORD
  valueFrom:
    secretKeyRef:
      key: password
      name: test-user.test-db.credentials.postgresql.acid.zalan.do