Databases¶
The platform provides databases as a Resource: declared once in the project, one instance with its own data per environment, backed up automatically. Your component receives the credentials as environment variables. OpenChoreo describes the general concept under Resource Dependencies.
Available types¶
| Type | What you get | Backup |
|---|---|---|
cnpg-postgres |
PostgreSQL (CloudNativePG), 2 instances by default, version 16, optional PostGIS 3.4 | continuous (WAL) + daily, 30 days |
mongodb |
MongoDB 7, one instance with authentication | nightly mongodump, 30 days |
Both types back up to object storage (OBS) under
apps/<project>/db/<resource>-<environment> and keep their data when the binding
to an environment is removed.
Do not use the type postgres
The bundled OpenChoreo type postgres is a demo (ephemeral storage, fixed
credentials, no backup) and unsuitable for project data.
1. Create a Resource¶
In the portal or as YAML:
apiVersion: openchoreo.dev/v1alpha1
kind: Resource
metadata:
name: myproject-db
namespace: onconnect
spec:
owner:
projectName: myproject
type:
kind: ClusterResourceType
name: cnpg-postgres
parameters:
database: app # database name (default: app)
owner: app # database user (default: app)
version: "16"
postgis: false
For MongoDB, type.name: mongodb and optionally parameters.database are enough.
2. Bind it to environments¶
A Resource only runs once it is bound to an environment. Bindings are not created automatically — one per environment:
apiVersion: openchoreo.dev/v1alpha1
kind: ResourceReleaseBinding
metadata:
name: myproject-db-development
namespace: onconnect
spec:
environment: development
owner:
projectName: myproject
resourceName: myproject-db
resourceRelease: myproject-db-<hash> # current release of the Resource
The current release is shown in the portal and in the Resource's status
(status.latestRelease.name). Changed parameters create a new release; it is taken
over to staging and production deliberately, as with components
(occ resource promote or set spec.resourceRelease on the binding).
Set sizes per environment in the binding under resourceTypeEnvironmentConfigs:
cnpg-postgres |
Default | mongodb |
Default | |
|---|---|---|---|---|
instances |
2 | storageSize |
2Gi | |
storageSize |
2Gi | memory |
1Gi | |
memory |
512Mi | |||
backupRetention |
30d |
3. Use it in the component¶
In workload.yaml you map the Resource's outputs to environment variables:
dependencies:
resources:
- ref: myproject-db
envBindings:
uri: DATABASE_URL
# or individually:
host: DB_HOST
port: DB_PORT
database: DB_NAME
username: DB_USER
password: DB_PASSWORD
| Output | cnpg-postgres |
mongodb |
|---|---|---|
host, port, database |
✔ | ✔ |
username, password |
✔ | — (contained in uri) |
uri |
postgresql://… |
mongodb://…?authSource=admin |
jdbcUri |
✔ | — |
Each environment automatically gets the credentials of its instance. The platform generates the passwords; they appear nowhere in the repository.
Data and recovery¶
- The database is reachable only inside the cluster. For maintenance or data imports, contact the platform team.
- Restores (e.g. PostgreSQL to a point in time before an error) are carried out by the platform team from the backups.