Configure Cloud SQL Proxy for DBO
Configure DBO on Google Kubernetes Engine (GKE) to use Cloud SQL Proxy for the upstream connection to Cloud SQL. Your application connects to DBO with its existing database username and password and no longer needs a Cloud SQL Proxy sidecar.

Application traffic passes through DBO and Cloud SQL Proxy before reaching Cloud SQL.
The application continues to authenticate with its existing database username and password. Cloud SQL Proxy secures the upstream connection from DBO to Cloud SQL.
Prerequisites
- An existing Cloud SQL instance connected to DBO in the Cast AI console. If you have not connected an instance, complete Cloud SQL quick start first.
- A GKE cluster with network access to the Cloud SQL instance with Workload Identity enabled.
kubectlconfigured to access the cluster.gcloudandhelmCLIs installed.- Permissions to create Google service accounts, grant IAM roles, and deploy DBO.
- An existing database username and password for the application.
Create the DBO identity
Cloud SQL Proxy needs a Google service account (GSA) with the Cloud SQL Client role. Workload Identity lets the DBO pod use this service account without a credential file.
Set the Google Cloud and DBO identity variables
export PROJECT_ID="your-project-id"
export DBO_SA_NAME="db-proxy"
export DBO_SA_EMAIL="${DBO_SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
export DBO_NAMESPACE="castai-db-optimizer"
export DBO_KSA_NAME="db-proxy"variable "project_id" {
type = string
default = "your-project-id"
}
variable "service_account_id" {
type = string
default = "db-proxy"
}Replace your-project-id with your Google Cloud project ID. Service account IDs must contain 6 to 30 characters and must be unique within the project.
Create the DBO service account
gcloud iam service-accounts create "${DBO_SA_NAME}" \
--project="${PROJECT_ID}" \
--display-name="DBO Cloud SQL Proxy" \
--description="Establishes the connection from DBO to Cloud SQL through Cloud SQL Proxy"resource "google_service_account" "dbo" {
project = var.project_id
account_id = var.service_account_id
display_name = "DBO Cloud SQL Proxy"
description = "Establishes the connection from DBO to Cloud SQL through Cloud SQL Proxy"
}Grant the Cloud SQL Client role to the DBO service account
gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
--member="serviceAccount:${DBO_SA_EMAIL}" \
--role="roles/cloudsql.client"resource "google_project_iam_member" "dbo_cloudsql_client" {
project = var.project_id
role = "roles/cloudsql.client"
member = google_service_account.dbo.member
}This role allows Cloud SQL Proxy to establish a secure connection to Cloud SQL. This authentication path does not require the Cloud SQL Instance User role or an IAM database user: the application continues to authenticate with its existing database username and password.
Allow the DBO Kubernetes service account to impersonate the DBO GSA
gcloud iam service-accounts add-iam-policy-binding "${DBO_SA_EMAIL}" \
--project="${PROJECT_ID}" \
--role="roles/iam.workloadIdentityUser" \
--member="serviceAccount:${PROJECT_ID}.svc.id.goog[${DBO_NAMESPACE}/${DBO_KSA_NAME}]"resource "google_service_account_iam_member" "dbo_workload_identity_user" {
service_account_id = google_service_account.dbo.name
role = "roles/iam.workloadIdentityUser"
member = "serviceAccount:${var.project_id}.svc.id.goog[castai-db-optimizer/db-proxy]"
}The Workload Identity pool is ${PROJECT_ID}.svc.id.goog. If your GKE cluster belongs to a different project, use that cluster's Workload Identity pool in the member string instead.
Create and annotate the DBO Kubernetes service account
If you used Terraform, make sure you have the environment variables from step 1 set before continuing.
kubectl create namespace "${DBO_NAMESPACE}" \
--dry-run=client -o yaml | kubectl apply -f -
kubectl create serviceaccount "${DBO_KSA_NAME}" \
--namespace="${DBO_NAMESPACE}" \
--dry-run=client -o yaml | kubectl apply -f -
kubectl annotate serviceaccount "${DBO_KSA_NAME}" \
--namespace="${DBO_NAMESPACE}" \
"iam.gke.io/gcp-service-account=${DBO_SA_EMAIL}" \
--overwriteRedeploy DBO
Configure DBO to run Cloud SQL Proxy and connect to your Cloud SQL instance.
Add the Cloud SQL Proxy Helm values
Add the following configurations to your existing db-proxy Helm values:
serviceAccountName: db-proxy
cloudSqlProxy:
enabled: true
privateIp: true
autoIamAuthn: falseserviceAccountNamespecifies the annotated DBO KSA.enabled: trueadds Cloud SQL Proxy to the DBO deployment.privateIp: trueconnects to Cloud SQL over private IP (set tofalseif using public IP).autoIamAuthn: falsedisables automatic IAM database authentication. Your application continues using its existing database credentials.
Redeploy DBO
Run the deployment command from the Cast AI console with your customized Helm values file.
Verify the deployment
Check that the DBO pods are running and all containers are ready:
kubectl get pods -n castai-db-optimizerConnect your application
Open the endpoint settings
In the Cast AI console, open the DBO instance and go to Settings → Endpoints.
Copy the connection details
In Caching configuration, copy the connection string or the DBO HOST and DBO PORT values.

Copy the DBO host and port from the Read/Write endpoint's Caching configuration.
Update the application connection settings
Update the application's database connection settings to use the copied DBO values. Keep the existing database name, username, and password unchanged.
See Connecting client applications for connection-string details.
Deploy and verify the application
Deploy the updated application and run its normal database reads and writes through the DBO host and port. Confirm that these operations succeed with its existing database username and password. You can also check the relevant cloud-sql-proxy container logs for accepted local connections to confirm that traffic traverses the new tunnel. If the application has a Cloud SQL Proxy sidecar, keep it until this application-level verification succeeds.
Remove an existing application sidecar
After verification, remove the application's Cloud SQL Proxy sidecar if it has one. Remove any volumes, settings, or credentials that only that sidecar used.
Your application no longer needs a Cloud SQL Proxy sidecar. DBO manages the upstream Cloud SQL connection.
Next steps
For a multi-application setup with separate identities and database permissions, continue to Isolate application identities for Cloud SQL.
Updated 7 hours ago
