Private IP

This page provides information about using private IP to connect to your Cloud SQL instances. For step-by- step instructions for configuring an instance to use private IP, see Configuring Private IP Connectivity.

Overview

When you configure a Cloud SQL instance to use private IP, you use private services access. Private services access is implemented as a VPC peering connection between your VPC network and the Google services VPC network where your Cloud SQL instance resides. IP traffic using private services access is never exposed to the public Internet.

The following diagram shows a Cloud SQL instance configured for private IP, and a Compute Engine instance on the peered customer VPC network using private services access to connect to the Cloud SQL instance.

Diagram overview of private IP configuration. Described in text above.

You can use private services access to connect to Cloud SQL instances from Compute Engine or Google Kubernetes Engine instances.

Benefits

Using private IP to connect to Cloud SQL gives you several advantages over using public IP addresses:

  • Lower network latency

    Private IP provides lower latency than public IP.

  • Improved network security

    Private services access traffic is never exposed to the public Internet.

Environment requirements

To use private IP, your network and application environment must meet the following requirements. In addition, setting up private IP for the first time requires some additional IAM permissions.

Network requirements

  • Resources that use private services access to connect to Cloud SQL instances, and their subnet, must be in the same region as the Cloud SQL instances.

  • You must allocate a range of IP addresses on your VPC before you peer with the Cloud SQL service. When you allocate addresses, you cannot use them for resources on your network; this prevents overlap between addresses used on your network and addresses used on the internal network where your Cloud SQL instances reside.

  • The network where the connecting resources are located must be a VPC network; legacy networks do not support VPC peering.

  • Shared VPC networks support private services access, and can be used to connect to a Cloud SQL instance using private IP.

  • Virtual Private Networks, including Cloud VPN, cannot be used to connect to Cloud SQL instances.

Application environment requirements

  • If you are connecting from GKE, you must be running GKE 1.8 or higher on a VPC-native cluster.

  • If you are connecting from App Engine, you must use flexible environment. You cannot use private IP to connect from standard environment.

API and IAM requirements

  • You must have enabled the Service Networking API for your project. If you are using shared VPC, you also need to enable this API for the host project.

    Enabling APIs requires the servicemanagement.services.bind IAM permission.

  • Establishing private services access requires the Network Administrator IAM role.

    After private services access is established for your network, you do not need the Network Administrator role to configure an instance to use private IP.

Security

Private services access traffic is encrypted and authenticated. For details, see Google Cloud’s virtual network encryption and authentication. If your security requirements mandate SSL/TLS certification that you manage, you can add SSL/TLS to your instance, using the instructions provided in Configuring SSL/TLS.

Overview of setting up private services access for your network

When you configure a Cloud SQL instance to use private IP for the first time on a specific network, you follow this general process to set up private services access for that network. The Cloud SQL instance creation process in the Google Cloud Platform Console guides you through the steps.

  1. Select the VPC network where the resources you want to connect from are located.

  2. If private services access has not yet been established for your VPC network and the Cloud SQL service, you must enable it. This requires an allocated IP address range from your network.

    1. If you have previously allocated an IP range to use, select it and proceed.

    2. If you want Cloud SQL to automatically allocate a range for you, select that option and proceed.

    3. If you want to manually select the IP range to allocate for the private connection, then you must use the gcloud command-line interface tool to create the IP range, then return to the Cloud SQL instance creation flow and select the newly created IP range. For information, see Allocating IP address ranges.

After you have established private services access, you can create a Cloud SQL instance configured to use private IP or configure private IP for an existing Cloud SQL instance by using the gcloud command-line tool or the Cloud SQL Admin API, in addition to the Google Cloud Platform Console. For more information, see Private IP.

Administration considerations

When you manage Cloud SQL instances using private IP, you should be aware of the following facts:

  • After you configure a Cloud SQL instance to use private IP, you cannot remove private IP capability from that instance.

  • You can configure an instance to use private IP at instance creation time or later.

  • Configuring an existing instance to use private IP, or changing the network it is connected to, causes the instance to be restarted. This causes a few minutes of downtime.

  • Cloud SQL instances are created in a producer network (a VPC network internal to Google). They are not created in your VPC network.

  • The private IP address of the Cloud SQL instance is static; it does not change.

  • When you configure an existing instance to use private IP, you cannot make any other updates to the instance at the same time.

  • Replicas inherit their private IP status from their primary instance. You cannot configure private IP directly on a replica.

  • You can use both public IP and private IP to connect to a Cloud SQL instance. Neither connection method affects the other; you must protect the public IP connection whether the instance is configured to use private IP or not.

  • You can use the Cloud SQL Proxy to connect to an instance that is also configured to use private IP. The proxy can connect using either the private IP address or a public IP address. If you use the Cloud SQL Proxy to connect to an instance that has both public and private IP addresses assigned, the proxy uses the public IP address by default. Learn more.

  • A private services access connection relies on a VPC Network Peering. However, you do not create the VPC Network peering explicitly, because the peering is internal to GCP. After you create the private services access connection, you can see its underlying VPC Network Peering on the VPC Network Peering page in the GCP Console, but you should not delete it unless you want to remove the private connection.

  • After you have established a private services access connection, and created a Cloud SQL instance with private IP configured for that connection, the corresponding (internal) subnet and range used by the Cloud SQL service cannot be modified or deleted. This is true even if you delete the peering and your IP range. After the internal configuration is established, any Cloud SQL instance created in that same region and configured for private IP uses the original internal configuration.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud SQL for PostgreSQL