Connecting GKE to Multiple Cloud SQL Instances for MySQL

Currently, my application is deployed on GKE and connected to a single Cloud SQL instance for MySQL 5.7. However, the database within this instance has reached the limit of 80,000 tables, impacting the performance of the application. In addition, I have around 100 schemas in the same database, and I aim to improve performance by dividing these schemas across two separate instances of Cloud SQL.

I would like guidance on how to configure my GKE deployment to connect to two Cloud SQL instances, both running MySQL 5.7.

  1. Configuring access control for the two Cloud SQL instances.
  2. Setting up Kubernetes Secrets to securely store database credentials.
  3. Updating my application's configuration to dynamically connect to the appropriate Cloud SQL instance based on the data it needs to access.

Any insights or reference materials would be greatly appreciated.

0 1 63
1 REPLY 1

Hello @ankit_fulzele,

Welcome to the Google Cloud Community!

Here's how to set up your GKE deployment to connect with two different Cloud SQL instances for better performance:

1. For each GKE deployment, create a service account to connect to its specific Cloud SQL instance. Assign the Cloud SQL Client role to each account. 
2. Use Kubernetes Secrets to securely store the database credentials for each Cloud SQL instance. Set up Kubernetes Secrets.
3. Update your application's configuration to dynamically select the correct Cloud SQL instance based on the required data. This involves configuring your application to retrieve the connection details (like database hostname, username, password, etc.) from Kubernetes Secrets and using these details to connect to the appropriate Cloud SQL instances.

For more details, check out these guides: