Kubegres allows setting custom environment variables. These variables can be used inside Kubegres resource configuration. And as they are set to the PostgreSql container, they can be accessed from your custom bash scripts running inside the container.
The available properties under "env:" follow Kubernetes' convention as described in the official doc.
The mandatory environment variables are:
- "env.name: POSTGRES_PASSWORD" : the password of the super user "postgres". This user is created by the official PostgreSql docker image.
- "env.name: POSTGRES_REPLICATION_PASSWORD" : the password of the "replication" user which is used by PostgreSql to replicate data between Primary and Replicas servers.
You can set your custom environment variables in Kubegres YAML. For example, you can create an environment variable which contains the password of a custom PostgreSql user. You can then access to that env-variable in an initialisation script in which you can create a custom PostgreSql user with that password.
Please see in the YAML below 2 custom env-variables "$POSTGRES_MY_DB_PASSWORD" and "$MY_OTHER_VAR". The env-variable $POSTGRES_MY_DB_PASSWORD is used in a PostgreSql initialisation script example.
apiVersion: kubegres.reactive-tech.io/v1 kind: Kubegres metadata: name: mypostgres namespace: default spec: replicas: 3 image: postgres:16.1 port: 5432 database: size: 200Mi env: - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: name: mySecretResource key: superUserPassword - name: POSTGRES_REPLICATION_PASSWORD valueFrom: secretKeyRef: name: mySecretResource key: replicationUserPassword - name: POSTGRES_MY_DB_PASSWORD valueFrom: secretKeyRef: name: mySecretResource key: myDbUserPassword - name: MY_OTHER_VAR value: "any_value"