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
KeyDescription
typeDatabase type (for example rds-mysql, rds-postgres, csql-postgres)
keys[].secretKeyWhich credential to read. Common values are username, password and hostname
keys[].envKeyThe 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


Did this page help you?