如何为 Google Compute Engine 实例获取动态子区域以克服 ZONE_RESOURCE_POOL_EXHAUSTED 错误

How to get a dynamic sub-zone for Google Compute Engine Instance to overcome ZONE_RESOURCE_POOL_EXHAUSTED error

我正在使用 Google Cloud Compute Engine API 在我的 Google Cloud App Engine 应用程序中创建虚拟机,如下所示:

compute.instances().insert(
        project=project,
        zone="europe-west2-b",
        body=config).execute()

我刚开始在 Google Cloud Logging AuditLogs 中看到以下日志:

2021-01-17 20:55:33.399 UTC
compute.googleapis.com
v1.compute.instances.insert
projects/supereye1/zones/europe-west2-b/instances/vm-c7fncyobtsg
supereye1@appspot.gserviceaccount.com
ZONE_RESOURCE_POOL_EXHAUSTED

如何在特定区域中创建动态区域分配的 Compute Engine 实例?

API需要指定区域,不提供“在区域内查找可用区域”。

失败时,您的代码(逻辑)可以select一个不同的区域并重试。

A Google 云区域是一个数据中心。想想一个购物中心的大小。区域之间的距离足够远,因此随意选择一个区域并不是一个好主意。延迟、负载均衡、容错等应该考虑这些因素来设计。

如果您只是启动一个独立的实例,那么您可能不关心您的实例在区域内的哪个位置运行。在这种情况下,您将需要设计区域 selection 并重试您的软件。