Inject Database Credentials
Give your application its database username, password and hostname automatically as environment variables, using the db dependency engine.
The db dependency engine connects your application to a database Component
provisioned on the platform. The platform reads each credential from the
database's own generated secret and sets it as an environment variable in your
pod. This is the same mechanism described in
Attach a Database to Your Application.
Add one entry under keys for each credential your application needs:
dependency:
db:
type: rds-mysql
keys:
- secretKey: username
envKey: MYSQL_USERNAME
- secretKey: password
envKey: MYSQL_PASSWORD
- secretKey: hostname
envKey: HOSTNAME| Key | Description |
|---|---|
type | Database type (for example rds-mysql, rds-postgres, csql-postgres) |
keys[].secretKey | Which credential to read. Common values are username, password and hostname |
keys[].envKey | The environment variable name your application reads |
keys[].namespace | (optional) read a database that lives in another namespace |
keys[].user | (optional) read credentials for a different database user |
keys[].instance | (optional) read credentials for a different database instance, for example when the Service has more than one |
The three optional overrides exist for the shared-database case: a reporting
application in its own namespace can read the credentials of a database that
belongs to another namespace, without that database being duplicated.
Related articles
- Application Dependencies — all dependency engines, and how to choose
- Dependency Configuration Examples — a minimal starter snippet
- Attach a Database to Your Application
- Secrets Manager
- IAM Service Accounts
- Kafka Access, ACLs and Topics
Updated about 1 month ago