I have a service which runs on Cloud Run, and a MYSQL, MongoDB databases on Compute Engine. Currently, I'm using public IP for connect between them, I want to use internal IP for improving performance, but i cant find solution for this problem, Please help me some ideas, Thanks.
4 Answers
According to official documentation Connecting to instances using advanced methods
If you have an isolated instance that doesn't have an external IP address (such as an instance that is intentionally isolated from external networks), you can still connect to it by using its internal IP address on a Google Cloud Virtual Private Cloud (VPC) network
However, if you check the services not yet supported for Cloud Run, you will find:
Virtual Private Cloud Cloud Run (fully managed) cannot connect to VPC network.

- 7,663
- 1
- 15
- 29
Now is supported. You can use VPC network connector (Beta):
This feature is in a pre-release state and might change or have limited support. For more information, see the product launch stages.
This page shows how to use Serverless VPC Access to connect a Cloud Run (fully managed) service directly to your VPC network, allowing access to Compute Engine VM instances, Memorystore instances, and any other resources with an internal IP address.
To use Serverless VPC Access in a Cloud Run (fully managed) service, you first need to create a Serverless VPC Access connector to handle communication to your VPC network. After you create the connector, you set your Cloud Run (fully managed) service configuration to use that connector.
Here how to create: Creating a Serverless VPC Access connector and here an overview about it: Serverless VPC Access example

- 2,348
- 2
- 27
- 41
-
Andre Araujo, great! let me try. – HoangThang May 29 '20 at 08:34
-
@HoangThang Did you test? Did work for you? If yes, please mark this answers as correct, so can help others... Thx. – Andre Araujo Jan 12 '22 at 16:00
-
Does anyone has tested it? I have this Scenario: Mongo db running in a container inside a Compute Enine --- Cloud Run Service running my API and using an VPC connector that use the default GCP configuration. Result: Mongo authenticate the user properly but kill the connection after a few moments – tufac2 Aug 17 '22 at 10:39
You can now do that by running this command upon deployment:
gcloud run deploy SERVICE --image gcr.io/PROJECT_ID/IMAGE --vpc-connector CONNECTOR_NAME
If you already have a Cloud Run deployment, you can update it by running the command:
cloud run services update SERVICE --vpc-connector CONNECTOR_NAME
More information about that here

- 1,501
- 1
- 14
- 20
Connecting from Cloud Run Managed to VPC private addresses is not yet supported.
This feature is in development and is called Serverless VPC Access. You can read more here.
If you have a Compute Engine instance running in the same VPC with a public IP address, you can create an SSH tunnel to connect to private IP addresses through the public instance. This requires creating the tunnel in your own code, which is easy to do.

- 74,467
- 6
- 95
- 159
-
3Hey John! Since this is now supported, I think the answer should be updated. – siamsot Jul 07 '20 at 07:48