【问题标题】:GCP API Gateway for Compute Engine适用于 Compute Engine 的 GCP API 网关
【发布时间】:2021-04-20 13:37:06
【问题描述】:

我在 api gateway 营销页面上找到了以下 sn-p。

所以我正在为在计算引擎上运行的应用设置 API 网关。由于找不到任何关于如何在 API 引擎上配置计算引擎的文档,我使用内部 DNS 创建了以下配置。enter link description here

swagger: "2.0"
info:
  title: API Endpoints
  description: API Endpoints
  version: 1.0.1
schemes:
  - https
produces:
  - application/json
paths:
  /indexes:
    get:
      summary: Return Search Indexes
      operationId: searchIndexes
      x-google-backend:
        address: http://my_internal_dns_for_compute_engine.c.myproject.internal/indexes
        path_translation: APPEND_PATH_TO_ADDRESS
      responses:
        "200":
          description: A successful response
          schema:
            type: string
        "403":
          description: Failed to authenticate

当我使用gcloud 部署配置时,出现以下错误

等待为 API 创建 API 配置 [my-api-config-v6] [my-api]...失败。
错误:(gcloud.beta.api-gateway.api-configs.create)等待服务 配置创建:后端 URL “http://my_internal_dns_for_compute_engine.c.myproject.internal/indexes”是 禁止:无法将请求路由到内部地址。

所以看起来不支持内部 DNS(显然)。

我的计算引擎实例只能通过 VPC 网络访问。如何将我的 api 网关连接到 VPC 网络以及如何通过它访问我的计算引擎?

【问题讨论】:

    标签: google-cloud-platform google-compute-engine google-vpc google-api-gateway


    【解决方案1】:

    今天,你无法做到这一点。您的 API 网关是无服务器服务,您不能在其上插入 serverless VPC connector。我已经与 Google 讨论过这个问题(例如,Cloud Scheduler、Cloud Task 和 PubSub 推送订阅也存在同样的问题)并且很快就会发生一些事情。敬请期待!!

    无论如何,现在要解决您的问题,您有 2 个解决方案(至少,一个确定,一个要测试)

    • 第一个(肯定的)解决方案是拥有一个“代理”。另一个具有公共访问权限的计算引擎,或具有无服务器 VPC 连接器的 Cloud Function/Cloud Run/App Engine 服务。 Cloud Function/Cloud Run/App Engine 更好,因为您可以使用 IAM 保护访问(无公共访问)
    • 第二种(测试)解决方案是部署Cloud Endpoint, I mean ESPv2 on Cloud Run,而不是使用API​​ 网关。事实上,API Gateway 目前是 Cloud Run 上 ESPv2 的托管解决方案。如果您在 Cloud Run 上插入无服务器 VPC 连接器,它应该可以工作。我写了an article on the ESPv2 & Cloud Run 用法。 如果我有时间,我将使用无服务器 VPC 连接器对其进行测试,然后通知您。否则,请尝试一下。

    编辑 1

    我已经测试了第二个解决方案,它适用于内部 IP(以及部署了 ESPv2 的 Cloud Run Endpoint 服务上的无服务器 VPC 连接器),而不是内部 DNS 名称。

    【讨论】:

    • 有什么新选择吗?我在 Google 搜索中找不到任何内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 2020-09-03
    • 1970-01-01
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    相关资源
    最近更新 更多