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. They can be on different subnets than the Cloud SQL instances.

  • VPC peering requires that subnets on the peered networks don’t share IP addresses; this is why you must allocate a range of IP addresses on your VPC before you peer with the Cloud SQL service.

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

  • Virtual Private Networks, or VPNs, 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.

  • 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.

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

  • Establishing private services access requires the following IAM permissions, which are included in the Network Administrator role:

    • compute.networks.list
    • compute.globalAddresses.list
    • compute.globalAddresses.create
    • servicenetworking.services.addPeering

    After private services access is established for your network, you do not need extra IAM permissions 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.

    If your VPC is a Shared VPC, the network can be in your project or the host project.

  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’ve previously allocated an IP range to use, you can select it and proceed.

    2. If you want to allow 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 more 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.

  • 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 cannot create the peering connection on the VPC peering page, because the network you are peering to is internal to GCP. After you create the peering connection, you can see it on the VPC peering page, and delete it.

  • You can use both public IP and private IP to connect to an 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, although it is not required. If you do use the Cloud SQL Proxy, you must also enable public IP for that instance.

  • You cannot use private IP with First Generation instances.

What's next

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

Send feedback about...

Cloud SQL for MySQL