google-cloud-platform - 使用 GCP Cloud VPN 在站点到站点 VPN 用例中将 GKE 集群 pod IP 地址隐藏在单个 IP 地址后面
问题描述
目前,我正在开发部署到谷歌云平台 GKE 集群的 nodejs 应用程序。此应用程序需要调用只能通过 VPN 访问的第 3 方 API,因此我必须建立一个到第 3 方 API 提供商网络的站点到站点 VPN。
我知道可以使用 GCP Cloud VPN 实现站点到站点 VPN,并且我以前有使用 GCP Cloud VPN 的经验。但对我来说问题是这个第 3 方 API 将只允许来自我的 VPC 的一个 IP 地址访问他们的网络,这是一个问题,因为 GKE 集群中的所有 pod 都有自己的临时 IP。
问题是我如何才能使从 GKE 集群到第 3 方 API 的传出 API 调用仅来自一个 IP 地址,以便第 3 方提供商管理员可以将该单个 IP 地址列入白名单以访问他们的 API?
我正在考虑使用一个 Linux 虚拟机作为 nat 路由器,这样对第 3 方 API 的 API 调用将首先通过这个 nat 路由器,然后从 nat 路由器到 Cloud VPN 网关。但是当我查看 VPC 路由表时,我就是看不到这种方法是如何实现的,因为在 VPC 路由表中我无法指定特定的网段作为源。我只能设置目的地和下一跳,这将影响 VPC 中的所有实例。
这是我的 VPC 的当前拓扑供参考:
这是可以在 GCP 中完成的事情,还是我以错误的方式看待问题?
谢谢你
解决方案
The question is that how I can make the outgoing API call from the GKE cluster to the 3rd party API comes only from one single IP address
Looks like Cloud NAT can solve your problem here.
If you have a private GKE cluster and Cloud NAT in the same region while creating/configuring the Cloud NAT you can allow traffics from that region to go through that Cloud NAT only.
This way, you have only one caller IP from your entire GKE cluster and the third-party API will not complain about that.
3rd Party API will only allow one single IP address from my VPC
为此,您可以保留一个外部 IP 地址并将其分配给您的 Cloud NAT 实例。事实上,这可以在创建 Cloud NAT 实例时即时完成。
有关如何创建和使用 Cloud NAT 的更多详细信息,您可以查看文档。使用 Cloud NAT 避免向外部互联网显示您的外部 IP 有很多好处。
以下是一些链接:
推荐阅读
- jackson - 我如何将 JSON 属性反序列化为 Jackson 中的 Java 对象
- java - 该项目使用与 Android Studio 2020.3 不兼容的 Gradle 2.10
- generics - 获取整数类型的双精度版本
- r - 如何使用预定义的布局保存 igraph 对象的边缘列表?
- python - 从 Excel 中的特定模式获取列数据
- python-3.x - 使用 Python 查找“.dng”图像分辨率
- vb6 - VB6 时间戳/日期差异()?
- spring-webflux - 数据库获取时,Spring Reactor 无法处理句柄操作
- selenium - 无法使用 Selenium Java 在 Jenkins Job 中找到文件
- flutter - 使用 LocalStorage 进行集成测试的正确方法?