Cloud SQL for Postgres
Runway supports provisioning and connecting to managed Cloud SQL for Postgres instances from your GKE workloads. Unlike unmanaged instances, Runway owns the lifecycle of the database — you do not need to enable PSC or obtain PSC details.
Request a managed Cloud SQL instance
Section titled “Request a managed Cloud SQL instance”File an MR to add your database to config/runtimes/gke/cloud-sql/managed.yml
in the Runway provisioner:
- name: my-service-db provider: GCP db_version: "POSTGRES_18" region: us-east1 zone: us-east1-b env_configuration: staging: instance_type: 2xsmall disk_size_gb: 10 backup_configuration: transaction_log_retention_days: 2 retained_backups_count: 3 production: instance_type: xsmall disk_size_gb: 10 backup_configuration: transaction_log_retention_days: 7 retained_backups_count: 7 labels: owner_email_handle: my-team department: eng-infra department_group: eng-infra-my-group product_category: my-categoryThe name you choose here is your database name and is referenced in the steps below.
Each environment under env_configuration also accepts prevent_db_deletion, which defaults to true and keeps the instance from being deleted.
Removing an instance, or one of its environments, takes two MRs: first set prevent_db_deletion: false for the environment(s) you are removing, merge, and let the apply run; then, in a follow-up MR, remove the entry (or the environment key) from managed.yml together with any postgres_instances references to it in workloads.yml.
An MR that removes the entry while prevent_db_deletion is still true on the default branch fails inventory validation.
See the managed Cloud SQL schema for all the available per-environment options.
Set up database credentials
Section titled “Set up database credentials”The application credentials (username and password) created for the app should be stored in Vault by the app owner and exposed to the workload as environment variables via workloadSecrets in gke-service.yaml — choose whatever variable names make sense for your application. See secrets management for details.
Grant your team read-only access
Section titled “Grant your team read-only access”Members of a Google group can query the database in Cloud SQL Studio using IAM authentication, with no password to share.
Add it to the relevant environment in managed.yml:
- name: my-service-db ... env_configuration: staging: iam_groups_ro: - my-team@gitlab.comMembers get SELECT on every table in every database on that instance and nothing else, writes and schema changes are rejected. Because access follows group membership, adding or removing someone needs no MR; changes take about 15 minutes to reach Cloud SQL.
Add the instance to your workload config
Section titled “Add the instance to your workload config”In config/runtimes/gke/workloads.yml,
add a postgres_instances key to your workload entry with the database name from the previous step:
your-service-gke: postgres_instances: - my-service-dbThis grants the GKE workload’s service account the IAM permissions required to connect to Cloud SQL.
Update your deployment file
Section titled “Update your deployment file”On Runway v2, two manifests describe the database. The Fairway manifest declares which databases your chart needs, and the Runway manifest says which Cloud SQL instance provides each of them.
Declare the databases in your Fairway manifest
Section titled “Declare the databases in your Fairway manifest”Declare one named binding per database under spec.infrastructure.postgresqlBindings:
spec: infrastructure: postgresqlBindings: - name: main presence: REQUIRED - name: workflow presence: OPTIONALThe name of a binding is the key that joins the two manifests.
Runway passes it through unchanged.
It must be a DNS label of at most 36 characters, and unique among your bindings.
presence is either REQUIRED or OPTIONAL.
Reference the instances in your Runway manifest
Section titled “Reference the instances in your Runway manifest”Add one entry per binding to the spec.infrastructure.cloudsqlInstances map in your deployment.yaml, keyed by the binding’s name:
apiVersion: runway/v2kind: RunwayManifestmetadata: name: your-service-gkespec: infrastructure: cloudsqlInstances: main: instanceConnectionName: us-east1:my-service-db databaseName: my_service workflow: instanceConnectionName: us-east1:my-service-workflow-db databaseName: workflowEach key is the name of the Fairway binding the instance provides, and follows the same rules: a DNS label of at most 36 characters. Each value has these fields:
| Field | Description |
|---|---|
instanceConnectionName |
<region>:<name>, where <name> is the database name from managed.yml. Runway adds the gitlab-runway-<env> project for the environment it deploys to. |
databaseName |
The logical Postgres database to connect to. |
Several entries may point at the same instance with different databaseName values.
A manifest can declare at most 100 instances.
runwayctl checks the two manifests against each other at deploy time:
| Fairway binding | Matching cloudsqlInstances entry |
Result |
|---|---|---|
REQUIRED |
yes | wired |
REQUIRED |
no | deploy fails |
OPTIONAL |
yes or no | wired when set |
| not declared | yes | deploy fails |
All mismatches are reported together, and nothing is deployed until they are fixed.
The deprecated cloudsqlInstance key
Section titled “The deprecated cloudsqlInstance key”Before cloudsqlInstances, a Runway manifest declared a single instance with the cloudsqlInstance key:
spec: infrastructure: cloudsqlInstance: instanceConnectionName: us-east1:my-service-db databaseName: my_servicecloudsqlInstance is kept for backwards compatibility only, and cannot be combined with cloudsqlInstances.
How Runway uses it depends on the Fairway manifest:
| Fairway manifest | Result |
|---|---|
The deprecated, unnamed spec.infrastructure.postgresql |
wired to values.infrastructure.postgresql |
postgresqlBindings with a single binding |
wired to that binding, with a warning |
postgresqlBindings with several bindings |
deploy fails |
The single-binding case lets you migrate the Fairway manifest to postgresqlBindings before the Runway manifest.
Runway uses the binding’s name, as if you had written cloudsqlInstances with that key, and logs a warning asking you to move the instance there:
WARNING: spec.infrastructure.cloudsql_instance is deprecated; binding it to the application's only PostgreSQL binding "postgresql". Move it to spec.infrastructure.cloudsql_instances[postgresql] instead.New services should use postgresqlBindings and cloudsqlInstances.
cloudsqlInstances, in turn, requires the Fairway manifest to declare postgresqlBindings.
cloudsqlInstance and cloudsqlInstances are only meaningful on GKE.
An EKS deployment ignores them with a warning; use RDS there instead.
Add cloudsql_instances to your gke-service.yaml. For managed instances, the project is always
gitlab-runway-<env> (for example, gitlab-runway-staging or gitlab-runway-production), the region
is whatever region you specified in managed.yml, and the instance name is your database name:
apiVersion: runway/v1kind: RunwayKubernetesDeployment
your-service-gke: serviceMixins: - "runway-gke.service-mixin"
cloudsql_instances: - instance_connection_name: gitlab-runway-<env>:<region>:<name>For example:
cloudsql_instances: - instance_connection_name: gitlab-runway-staging:us-east1:my-service-dbConnecting to Cloud SQL
Section titled “Connecting to Cloud SQL”Runway runs one Cloud SQL Auth Proxy sidecar per binding, named cloud-sql-proxy-<name>.
With the scalar form, the deprecated cloudsqlInstance gets a single sidecar named cloud-sql-proxy.
The proxies listen on localhost, on sequential ports starting at 5432, in the alphabetical order of the binding names.
Adding or removing an instance can therefore change the ports of the others, so read the port from your configuration instead of hard-coding it.
Runway writes the connection settings into your Helm values, so you do not configure them yourself:
- For each binding,
values.infrastructure.postgresqlBindings[<name>]gets thehost(127.0.0.1),port,databaseNameandusername. - With the scalar form,
values.infrastructure.postgresqlgets the same fields.
The proxy authenticates with IAM database authentication as your workload’s service account, so there is no password and no secret to manage.
Runway sets username to the workload’s IAM database user, gke-<workload ID>@<Runway Project ID>.iam, for example gke-my-service-gke@gitlab-runway-staging.iam.
Everything else on a binding, such as clientName, maxConns or queryExecMode, is yours to set in your chart’s values and is preserved.
If you set host, port, databaseName, username, secretRef, poolHost or poolPort, Runway overwrites them and logs a warning naming each field.
Connecting to a managed Cloud SQL instance works the same as for unmanaged instances.
The Cloud SQL Auth Proxy exposes databases on localhost with sequential ports starting at 5432:
| Instance | Port |
|---|---|
| First | 5432 |
| Second | 5433 |
| Third | 5434 |
Connect using:
- Host:
127.0.0.1 - Port:
5432(first instance),5433(second), etc. - Username and password via environment variables (see secrets management)
Restore validation
Section titled “Restore validation”The provisioner creates a GitLab project on ops.gitlab.net for every Postgres instance. Each project has a scheduled pipeline that restores the latest backup to a separate Cloud SQL instance and, optionally, runs a data validation query against the restored database.
For production Cloud SQL instances, an alert will be fired if a restore validation pipeline was not triggered in the last 24 hours or if a pipeline has started but not completed within 2 hours.
The data validation query is optional and is configured in the env_configuration.<env>.backup_configuration.restore_validation field:
- Omitted entirely - the scheduled pipeline still runs and restores the latest backup, but no data validation query is executed.
- Set with
database,user,vault_secret_name,vault_secret_key, andquery- the restore test runs and the validation query is executed against the restored database.
Unlike the Cloud Run runtime, managed Cloud SQL on GKE does not auto-create the validation user. You must supply credentials for a user that exists in the source database with privileges to run the validation query. The password is read from a Vault KV v2 secret, where:
- The secret name (path) is
env/<environment>/service/<runway_service_id>/<vault_secret_name>. <vault_secret_key>is the key inside that secret’s data whose value holds the password.
runway_service_id is auto-derived from the workload that owns this Cloud SQL instance - you only need to supply vault_secret_name (the last path segment) and vault_secret_key (the key within the secret).
When a validation query is provided, it should return 1 row of at least 2 columns to pass validation. The two columns can be data of any kind and will be printed in the CI job. Users can generate summary statistics and expose them through the two columns (see example below). The query should return no rows if the data is invalid. An alert will be fired if the validation query fails on production.
- name: runway-db-foo ... env_configuration: staging: backup_configuration: restore_validation: database: runway user: validator vault_secret_name: cloudsql-restore-validation vault_secret_key: password query: "SELECT COUNT(*) AS row_count, MAX(timestamp_column) AS most_recent_timestamp FROM your_table WHERE timestamp_column >= NOW() - INTERVAL '1 DAY' LIMIT 1;"Remove the instance
Section titled “Remove the instance”Removing a managed instance takes two provisioner MRs, because the instance has deletion protection enabled by default.
-
Disable deletion protection. In
config/runtimes/gke/cloud-sql/managed.yml, setprevent_db_deletion: falsefor every environment of the instance. Merge the MR and let the apply run. An MR that removes the instance whileprevent_db_deletionis stilltrue(or unset) on the default branch fails inventory validation.config/runtimes/gke/cloud-sql/managed.yml - name: runway-db-foo...env_configuration:staging:prevent_db_deletion: falseproduction:prevent_db_deletion: false -
Remove the instance. In a follow-up MR, remove the entry from
managed.ymltogether with the instance name in thepostgres_instanceslist of your workload inconfig/runtimes/gke/workloads.yml. Stop your service from connecting to the instance before you merge. Applying the MR destroys the instance, its networking and IAM bindings, and its restore validation resources, including the GitLab project on ops.gitlab.net. -
Ask an SRE to clean up the restore validation metrics. The restore validation pipeline pushes its metrics to the Pushgateway on
blackbox-01-inf-gprd, which keeps the last pushed values indefinitely. Once the instance is gone, nothing updates them and theNoRestorePipelineStartedalert fires for it 24 hours after the last pipeline ran. Ask the Runway team for an SRE to delete the instance’srunway_csql_restoregroup. The steps are in the Pushgateway runbook. The group isjob="runway_csql_restore"withtier="db",type="postgres"andresourceset to the instance name.For example, on
blackbox-01-inf-gprd, replace<resource>with the value of theresourcelabel (such asrunway-db-foo-production-us-east1):Terminal window curl -X DELETE http://127.0.0.1:9091/metrics/job/runway_csql_restore/tier/db/type/postgres/resource/<resource>