Skip to content
Kapten
Esc
↑↓navigate↵open⌘Jpreview
On this page

Add a database

Create a PostgreSQL, MySQL, MongoDB or Redis database in an environment and connect your application to it with the secrets Kapten generates.

Choose the engine

In your environment, create a database and pick PostgreSQL, MySQL, MongoDB or Redis.

Name it

Enter its name, the engine version, and optionally the name of the logical database to create in it. The name decides the names of its secrets.

Choose provisioning and access

  • In cluster runs the database on the environment’s cluster. Managed provisions your cloud provider’s database service.
  • Private keeps it reachable from inside the cluster only. Choose Public only if something outside the cluster must connect to it.

Size it

Set its CPU, memory and disk.

Choose the options

Turn on disk encryption, high availability and backups as needed, then review and create the database.

Connect your application

Kapten adds the database’s credentials to the environment as secrets. For a database named main, every component of the environment gets:

KAPTEN_DATABASE_MAIN_HOST
KAPTEN_DATABASE_MAIN_USERNAME
KAPTEN_DATABASE_MAIN_PASSWORD
KAPTEN_DATABASE_MAIN_DATABASE
KAPTEN_DATABASE_MAIN_CONNECTION_STRING

Read them in your code, or map them to the name your framework expects with a component variable. Redeploy applications that were running before the database existed so they pick up the new secrets.

// Node.js, with the pg package
import pg from "pg";

const pool = new pg.Pool({
  connectionString: process.env.KAPTEN_DATABASE_MAIN_CONNECTION_STRING,
});

See Database secrets for how the names are formed.

Was this page helpful?