Issue Connecting to Cloud SQL Postgres using Private IP from GKE
I was able to connect to Cloud SQL Postgres by creating a VPC-native cluster as suggested by @patrick-w.
My VPC subnetwork creation was modified to include two secondary ranges:
gcloud compute networks subnets create stg-vpc-us-central1 \
--network stg-vpc \
--region us-central1 \
--range 10.10.0.0/16 \
--secondary-range stg-vpc-us-central1-pods=10.11.0.0/16,stg-vpc-us-central1-services=10.12.0.0/16
And my cluster creation command was modified to enable ip-alias
, and added details of the secondary ranges to use.
gcloud -q container clusters create cluster-1 \
--zone us-central1-a \
--num-nodes 3 \
--enable-ip-alias \
--network stg-vpc \
--subnetwork stg-vpc-us-central1 \
--cluster-secondary-range-name stg-vpc-us-central1-pods \
--services-secondary-range-name stg-vpc-us-central1-services