我正在做一个 PoC 来连接Google App Engine
到 在. 用于测试的示例应用程序来自https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/cloud-sql/mysql/sqlalchemy/README.mdCloudSQL instance
Private IP
SharedVPC
我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 Access
和角色Network Compute User
App Engine Default Service account
VPC Host Project
<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
相同的设置CloudRun
并CloudSQL
为我工作,但在GAE
. 有什么建议可以解决这个问题吗?