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
Applicationmanifest. - The names of your
organization,organizational-unit,environmentandproject.
Steps
-
Create the
Databasemanifest.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 instancesDo not write the
computedblock. The platform fills it with values such as the internal host name. -
Grant the application access. By default, no application can reach the database. Add
accessControl.databaseto theApplication.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 -
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
- Run Database Migrations
- Control Costs: size the database.
Databasereference