从应用程序引擎到使用私有IP和无服务器VPC访问的CloudSQL的连接问题



我正在执行PoC,以便从Google App Engine连接到CloudSQL instance,并在SharedVPC上运行Private IP。测试的示例应用程序来自
https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/cloud-sql/mysql/sqlalchemy/README.md

我的Serverless VPC Connector Range如下

$ gcloud compute networks vpc-access connectors list --region=us-central1
CONNECTOR_ID       REGION       NETWORK          IP_CIDR_RANGE    MIN_THROUGHPUT  MAX_THROUGHPUT  STATE
testserverlessvpc  us-central1  kube-shared-vpc  192.168.60.0/28  200             300             READY

Private IP Range如下

$ gcloud compute addresses list --global --filter="purpose=VPC_PEERING"
NAME                 ADDRESS/RANGE     TYPE      PURPOSE      NETWORK           REGION  SUBNET  STATUS
cloudsqltestrangenew  10.0.100.0/20    INTERNAL  VPC_PEERING  kube-shared-vpc                   RESERVED

MySQL实例如下

$ gcloud sql instances list
NAME       DATABASE_VERSION  LOCATION       TIER         PRIMARY_ADDRESS  PRIVATE_ADDRESS  STATUS
mysql2           MYSQL_5_7         us-central1-b  db-f1-micro  -            10.0.100.5       RUNNABLE

app.standard.yaml如下

runtime: python37
service: appcentralpri
env_variables:
CLOUD_SQL_CONNECTION_NAME: projectname:us-central1:mysql2
DB_USER: guestdb
DB_PASS: password
DB_NAME: testdb
DB_HOST: 10.0.100.5:3306
vpc_access_connector:
name: projects/hostproject-26a2/locations/us-central1/connectors/testserverlessvpc

部署进行得很好,日志中没有遇到错误

gcloud app deploy app.standard.yaml

然而,当我尝试连接到应用程序端点时,页面无法使用"访问;"找不到服务器">

我已经在VPC Host Project上将VPC AccessNetwork Compute User的角色赋予了以下App Engine Default Service account

<hostproject>-26a2@appspot.gserviceaccount.com 

更新

在app.yaml中也添加了以下内容,但没有运气

env_variables:
GAE_USE_SOCKETS_HTTPLIB : 'anyvalue'

https://cloud.google.com/appengine/docs/standard/python/sockets#making_httplib_use_sockets

CloudRunCloudSQL的相同设置对我有效,但对GAE很吃力。有什么解决这个问题的建议吗?

您的app.yaml文件格式错误。vpc_access_connector:需要位于根级别。这里它被当作一个环境变量值。

runtime: python37
service: appcentralpri
env_variables:
CLOUD_SQL_CONNECTION_NAME: projectname:us-central1:mysql2
DB_USER: guestdb
DB_PASS: password
DB_NAME: testdb
DB_HOST: 10.0.100.5:3306
vpc_access_connector:
name: projects/hostproject-26a2/locations/us-central1/connectors/testserverlessvpc

相关内容

  • 没有找到相关文章

最新更新