【问题标题】:GAE http request to GCE via Serverless VPC Connector通过无服务器 VPC 连接器向 GCE 发出 GAE http 请求
【发布时间】:2020-06-14 06:07:31
【问题描述】:

我有一个 Google App Engine 应用程序(python 2.7 - 这是一个正在升级的旧项目!),它需要对 Google Compute Engine 上的 Elastisearch 实例进行查询。我可以毫无问题地使用 GCE 公共 IP 地址发出请求,但我不希望将 GCE 实例暴露给公共互联网。

  • 应用引擎应用位于美国中部地区
  • 计算引擎实例位于区域 us-central1,区域 us-central1-f
  • 计算引擎实例位于 vpc 网络“默认”中。 (不是旧版网络)
  • 我在默认网络上的 us-central1 中设置了一个无服务器 VPC 连接器。
  • 我已将应用引擎 app.yaml 设置为使用连接器。

但是对计算引擎私有 IP 地址 (10.128.0.2) 的 http 请求连接失败,并且计算引擎的内部 DNS 名称上的 DNS 查找失败 编辑:dns 查找确实使用 @ 987654321@.

error: An error occured while connecting to the server: Unable to connect to server at URL: http://10.128.0.2:9200/indexname

使用公网 IP 地址时同样的请求成功(当我在端口 9200 上打开 VPC 防火墙时)。

来自应用引擎应用配置的片段:

runtime: python27
api_version: '1'
env: standard
threadsafe: false
instance_class: F4

network:
  name: default
vpc_access_connector:
  name: >-
    projects/myproject/locations/us-central1/connectors/connector0301

gcloud beta --account="myaccount" --project="myproject" 应用描述:

authDomain: gmail.com
codeBucket: staging.myproject.appspot.com
databaseType: CLOUD_DATASTORE_COMPATIBILITY
defaultBucket: myproject.appspot.com
defaultHostname: myproject.appspot.com
featureSettings:
  splitHealthChecks: true
  useContainerOptimizedOs: true
gcrDomain: us.gcr.io
id: myproject
locationId: us-central
name: apps/myproject
servingStatus: SERVING

gcloud beta --account="myaccount" --project="myproject" 计算实例描述(仅网络 sn-p):

networkInterfaces:
- accessConfigs:
  - kind: compute#accessConfig
    name: External NAT
    natIP: SNIPPED
    networkTier: PREMIUM
    type: ONE_TO_ONE_NAT
  fingerprint: M087cXbOWII=
  kind: compute#networkInterface
  name: nic0
  network: https://www.googleapis.com/compute/beta/projects/myproject/global/networks/default
  networkIP: 10.128.0.2
  subnetwork: https://www.googleapis.com/compute/beta/projects/myproject/regions/us-central1/subnetworks/default

gcloud beta --account="myaccount" --project="myproject" 计算网络 vpc-access

connectors list --region=us-central1
CONNECTOR_ID   REGION       NETWORK  IP_CIDR_RANGE  MIN_THROUGHPUT  MAX_THROUGHPUT  STATE
connector0301  us-central1  default  10.8.0.0/28    200             300             READY

gcloud beta --account="myaccount" --project="myproject" 计算网络 vpc-access 连接器描述 connector0301 --region=us-central1

ipCidrRange: 10.8.0.0/28
maxThroughput: 300
minThroughput: 200
name: projects/myproject/locations/us-central1/connectors/connector0301
network: default
state: READY

gcloud --account="myaccount" --project="myproject" 计算防火墙规则描述默认允许内部

allowed:
- IPProtocol: tcp
  ports:
  - 0-65535
- IPProtocol: udp
  ports:
  - 0-65535
- IPProtocol: icmp
creationTimestamp: '2020-02-11T11:18:09.906-08:00'
description: Allow internal traffic on the default network
direction: INGRESS
disabled: false
id: '1434668200291681054'
kind: compute#firewall
logConfig:
  enable: true
name: default-allow-internal
network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default
priority: 65534
selfLink: https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/default-allow-internal
sourceRanges:
- 10.128.0.0/9
- 10.8.0.0/28

无服务器 VPC 连接器是否不适用于内部 IP http 请求?

【问题讨论】:

  • 更新:DNS 解析确实有效,所以我觉得 VPC 连接器对 http 请求的内部 IP 没有帮助。

标签: google-app-engine google-cloud-platform google-compute-engine


【解决方案1】:

无服务器 VPC 连接器是否不适用于内部 IP http 请求?

无服务器 VPC 连接器适用于在 python37 运行时中使用 urllib.request 的内部 IP http 请求,但在 python27 运行时中不使用 google.appengine.api 中的 urllib2urlfetch。 (提醒urllib2 uses urlfetch under the hood on app engine python27

由于这是一个从 python27 缓慢迁移到 python37 的旧项目的一部分,所以现在我将内部 ip http 请求放入一个单独的服务中,以便它们可以使用新的运行时。

【讨论】:

  • 嗨!我有一个和你类似的问题。我正在尝试建立从 Cloud Function 到 App Engine 端点的私有连接。我已将 Serverless VPC 连接器附加到该函数并强制 App Engine 仅侦听内部流量,但请求未到达 App Engine。我的项目是 Python 3,我使用 requests 模块从 Cloud Function 发送请求。我也试过urllib.request,但也没有用。你知道如何解决这个问题吗? google.appengine.api.urlfetch 是否可用于 Python 3,以便我可以从我的云函数中使用它?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-30
  • 1970-01-01
  • 2023-03-20
  • 2018-08-22
  • 2015-09-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多