gcloud 计算引擎到应用程序引擎的连接仅适用于启用“外部 IP”的情况

问题描述 投票:0回答:2

我使用 gcloud 计算引擎作为我的数据库,使用应用程序引擎作为我的服务器。如果我在 CE 上启用临时外部 IP,我的服务器可以通过内部网络进行连接。我还可以从外部访问我的服务器。但是,如果我将 CE 配置为“仅内部”,则我的服务器无法访问 CE,即使服务器使用内部网络,且 CE 配置为临时外部 IP。服务器对 CE 实例的临时 IP 地址一无所知。总结一下:

具有默认网络(10.156.0.X 和临时外部 IP)的 CE -> App Engine 服务器(通过 10.156.0.X)= 有效!

具有默认网络的 CE(仅限 10.156.0.X)-> App Engine 服务器 = 不起作用

我本以为简单地删除外部IP地址不会对内部网络产生影响!我目前正在我的服务器上使用无服务器 VPC 连接器来访问 GCE。两者都是同一项目的一部分。

具有外部IP配置:

  "networkInterfaces": [
    {
      "name": "nic0",
      "network": "projects/x/global/networks/default",
      "accessConfigs": [
        {
          "name": "External NAT",
          "type": "ONE_TO_ONE_NAT",
          "natIP": "xx.xxx.xx.xx",
          "kind": "compute#accessConfig",
          "networkTier": "STANDARD",
          "setPublicPtr": false
        }
      ],
      "subnetwork": "projects/x/regions/europe-west3/subnetworks/default",
      "networkIP": "10.156.0.6",
      "fingerprint": "tkgs6oiAL8E=",
      "kind": "compute#networkInterface"
    }
  ]

无需外部IP

  "networkInterfaces": [
    {
      "name": "nic0",
      "network": "projects/x/global/networks/default",
      "subnetwork": "projects/x/regions/europe-west3/subnetworks/default",
      "networkIP": "10.156.0.6",
      "fingerprint": "uWRkQpIa-fs=",
      "kind": "compute#networkInterface"
    }
  ],

数据库防火墙配置:

{
  "allowed": [
    {
      "IPProtocol": "tcp",
      "ports": [
        "0-65535"
      ]
    },
    {
      "IPProtocol": "udp",
      "ports": [
        "0-65535"
      ]
    },
    {
      "IPProtocol": "icmp"
    }
  ],
  "creationTimestamp": "2020-03-23T08:36:03.630-07:00",
  "description": "Allow internal traffic on the default network",
  "direction": "INGRESS",
  "disabled": false,
  "enableLogging": false,
  "id": "x",
  "kind": "compute#firewall",
  "logConfig": {
    "enable": false
  },
  "name": "default-allow-internal",
  "network": "projects/x/global/networks/default",
  "priority": 65534,
  "selfLink": "projects/x/global/firewalls/default-allow-internal",
  "sourceRanges": [
    "0.0.0.0/0",
    "10.128.0.0/9",
    "10.8.0.0/28"
  ],
  "sourceServiceAccounts": [
    "[email protected]"
  ]
}

服务器防火墙配置:

Priority
1000

Action on match
ALLOW

IP Range
10.156.0.6

Description
Something

App Engine 配置:

runtime: nodejs16
env: standard
instance_class: F4
handlers:
  - url: .*
    script: auto
  - url: .*
    script: auto
env_variables:
  ACCESS_CONTROL_ALLOW_ORIGIN: 'https://x.com'
  ...
  DB_PATH_INTERNAL: 'http://10.156.0.6:8529'
  ...
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: automatic
  min_pending_latency: automatic
  max_pending_latency: automatic
network:
  name: default
vpc_access_connector:
  name: projects/x/locations/europe-west3/connectors/x
  egress_setting: private-ip-ranges
service_account: [email protected]
google-compute-engine gcloud
2个回答
0
投票

10.0.0.0
(10/8) 开头的 IP 地址是私有 IP 地址 RFC 1918。即使 App Engine 和您的 VPC 使用相同的地址范围,它们也不会使用相同的网络。每个网络都是私有的。

为了让 App Engine 连接到 VPC 中的实例(不使用外部 IP 地址),您必须配置 Serverles VPC 访问

注意:如果两个系统都使用 10.x.x.x 地址,那么您可能会遇到称为重叠网络的问题。您可能需要配置一个范围不重叠的新 VPC。

您可以对等模式 VPC 网络和自动模式 VPC 网络 比如默认网络。但是,您必须确保没有任何 自定义模式 VPC 网络中的子网与地址重叠 自动模式VPC网络空间(10.128.0.0/9)

专有网络规格


0
投票

所以我能够解决我的问题。概念性问题(基于我的非专家意见)是 App Engine 标准不断更改 IP 地址。因此,我的服务器的响应(Compute Engine VM)永远无法找到它来自的节点服务器(App Engine)。因此,我需要以某种方式“锁定”服务器/中间件的 IP 地址,以便数据库的响应可以找到它。

有几个问题需要解决:

  1. 这篇文章帮助我找到了问题:

[https://cloud.google.com/appengine/docs/standard/outbound-ip-addresses][1]

App Engine 标准环境下的出站服务,例如 URL Fetch、Sockets 和 Mail API 使用大量 IP 地址。该池中的 IP 地址范围受常规限制 变化。事实上,来自同一应用程序的两个连续 API 调用 可能看起来源自两个不同的 IP 地址。

如果您需要知道与出站流量关联的 IP 地址 从您的服务中,您可以找到当前的 IP 地址范围 为您的服务设置静态 IP 地址。 https://cloud.google.com/vpc/docs/configure-private-google-access

  1. 配置计算引擎虚拟机

网络配置下: '网络': '默认', 'Subnetwork':'上面创建的子网名称' “内部 IP 地址”:从上面的子网范围中选择一个 IP “主要内部 IPv4 地址”:临时地址 “外部 IP 地址”:无

  1. 部署 App Engine:

vpc_access_connector:名称: 项目/PROJECT_ID/位置/REGION/连接器/CONNECTOR_NAME egress_setting:所有流量

确保“egress_setting”设置如上。

ServerlessVPC 连接器的模糊说明让我感到困惑,它没有说明需要创建出站 IP 地址。此外,我为虚拟机创建了一个子网,但没有创建出站 IP 地址。

© www.soinside.com 2019 - 2024. All rights reserved.