CloudRun with CloudSQL Private IP
Short note on step to deploy my CloudRun Project on Google GCP to connect CloudRun with CloudSQL Private IP.
Select Menu Cloud Build > Setting
Then Enabled Cloud Run.
Next, Create Service Account
Select Menu IAM > Service Account
Then Create Service Account
Create Key to use with Gitlab Build and deploy because you need to deploy Cloud Run from cloud container. You can see the detail in my other note.
Next, Create Database using Cloud SQL.
Select Private IP and Network default (or your VPC Network)
You will get the Public IP and Private IP after your DB is created. This may take awhile.
As you can see, You got Private IP > 10.112.17.11
Next, Go to Manu VPC > Serverless VPC and select Create Connector
Create Serverless VPC to let your CloudRun communicate with CloudSQL
- You need to use the same region as your DB and CloudRun.
- The IP Range MUST cover your Database IP. In this note is 10.112.0.0/28 (Your Database Private IP is 10.112.17.11)
- Don’t forget to set machine size in scaling setting.
Next, Create CloudRun and select Serverless VPC that you just created.
Select Connection tab to set VPC network.
Select VPC network you create on last step.
If everything is fine, your application should connect to your DB with Private IP without a problem.