Skip to main content

Provision a Database

Create a managed AlloyDB (PostgreSQL) database and give an application access to it. The platform sets up the network, firewall rules and encryption. It turns on automated backups for each new cluster. Google sets the schedule and the retention.

Prerequisites​

  • An Application manifest.
  • The names of your organization, organizational-unit, environment and project.

Steps​

  1. Create the Database manifest.

    apiVersion: lowops.manifests.v1
    kind: Database
    metadata:
    name: accounts-db
    project: login-svc
    environment: development
    organizational-unit: retail-banking
    organization: fincorp
    spec:
    databases:
    - name: accounts
    extensions: ["uuid-ossp", "pgcrypto"] # AlloyDB only
    alloydb: # exactly one of alloydb or spanner
    cpuCount: 4
    clusterSize: 1 # 1 = single primary; >1 adds read-pool instances

    Do not write the computed block. The platform fills it with values such as the internal host name.

  2. Grant the application access. By default, no application can reach the database. Add accessControl.database to the Application.

    spec:
    accessControl:
    database:
    name: accounts-db # the Database manifest name
    schema: accounts # a logical database from spec.databases
    privileges: [USAGE, CREATE]
    readOnly: false # true connects to a read replica
    secretSource:
    envVar: DATABASE_CONNECTION_STRING
  3. Commit both manifests in one pull request and merge it.

Verify​

The platform creates a database user for the application. It stores the credentials in Secret Manager. It restarts the application with the connection string in DATABASE_CONNECTION_STRING.

Next​