0

我正在做一个 PoC 来连接Google App Engine到 在. 用于测试的示例应用程序来自https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/cloud-sql/mysql/sqlalchemy/README.mdCloudSQL instancePrivate IPSharedVPC

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 UserApp Engine Default Service accountVPC 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

相同的设置CloudRunCloudSQL为我工作,但在GAE. 有什么建议可以解决这个问题吗?

4

1 回答 1

1

您的 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
于 2020-11-13T12:06:46.367 回答