* docs: add guides to view middleware data * docs: add guide for grafana * docs: add guide for otel and integration guides for other middleware * docs: add guide for elasticsearch * docs: update based on suggestions * Update zh.ts * docs: update content * docs: resolve conflict
2.8 KiB
outline, description
| outline | description | ||
|---|---|---|---|
|
Learn how to integrate your app with the built-in PostgreSQL service in Olares. |
Integrate with PostgreSQL
Use Olares PostgreSQL middleware by declaring it in OlaresManifest.yaml, then mapping the injected values to your container environment variables.
:::info PosgreSQL installed PostgreSQL service has been installed by default. :::
Configure OlaresManifest.yaml
In OlaresManifest.yaml, add the required middleware configuration.
- Use the
scriptsfield to specify scripts that should be executed after the database is created. - Use the
extensionsfield to add the corresponding extension in the database.
:::info Variable injection in scripts
The OS provides two variables, $databasename and $dbusername, which will be replaced by Olares Application Runtime when the command is executed.
:::
Example
middleware:
postgres:
username: immich
databases:
- name: immich
extensions:
- vectors
- earthdistance
scripts:
- BEGIN;
- ALTER DATABASE $databasename SET search_path TO "$user", public, vectors;
- ALTER SCHEMA vectors OWNER TO $dbusername;
- COMMIT;
Inject environment variables
In your deployment YAML, map the injected .Values.postgres.* fields to the environment variables your app uses.
Example
containers:
- name: my-app
env:
# The database name configured in OlaresManifest, specified in middleware.postgres.databases[i].name
# NOTE: Replace <dbname> with the actual name defined in the Manifest (e.g., immich)
- name: DB_POSTGRESDB_DATABASE
value: {{ .Values.postgres.databases.<dbname> }}
# Host
- name: DB_POSTGRESDB_HOST
value: {{ .Values.postgres.host }}
# Port
- name: DB_POSTGRESDB_PORT
value: "{{ .Values.postgres.port }}"
# Username
- name: DB_POSTGRESDB_USER
value: {{ .Values.postgres.username }}
# Password
- name: DB_POSTGRESDB_PASSWORD
value: {{ .Values.postgres.password }}
PostgreSQL Values reference
PostgreSQL Values are predefined environment variables injected into values.yaml during deployment. They are system-managed and not user-editable.
| Key | Type | Description |
|---|---|---|
.Values.postgres.host |
String | PostgreSQL database host |
.Values.postgres.port |
Number | PostgreSQL database port |
.Values.postgres.username |
String | PostgreSQL database username |
.Values.postgres.password |
String | PostgreSQL database password |
.Values.postgres.databases |
Map<String,String> | The requested database name is used as the key. For example, if you request app_db, the value is available at .Values.postgres.databases.app_db |