无法使用自定义网络启动 GKE(Google 容器引擎)集群

Unable to launch a GKE (Google Container Engine) cluster with a custom network

我正在尝试使用 "custom" 类型的网络启动 GKE 集群,而不是 "auto" 类型的网络。

我使用以下命令启动我的集群:

$ gcloud container clusters create --cluster-ipv4-cidr=10.0.0.0/14 --network=ttest --subnetwork=ttest --num-nodes=1 jt

我收到以下错误:

Creating cluster jt...done.
ERROR: (gcloud.container.clusters.create) Operation [<Operation
 name: u'operation-1467037655793-e319dc5e'
 operationType: OperationTypeValueValuesEnum(CREATE_CLUSTER, 1)
 selfLink: u'https://container.googleapis.com/v1/projects/TRUNCATED/zones/us-east1-b/operations/operation-1467037655793-e319dc5e'
 status: StatusValueValuesEnum(DONE, 3)
 statusMessage: u'Requested CIDR 10.0.0.0/14 is not available in network "ttest".'
 targetLink: u'https://container.googleapis.com/v1/projects/TRUNCATED/zones/us-east1-b/clusters/jt'
 zone: u'us-east1-b'>] finished with error: Requested CIDR 10.0.0.0/14 is not available in network "ttest".

它似乎想要一个具有 /14 地址范围的网络或子网,所以命令 应该 理想地工作,但它没有。

这很奇怪,因为我的网络是这样的:

测试网络:

$ gcloud compute networks describe ttest

autoCreateSubnetworks: false
creationTimestamp: '2016-06-27T07:25:03.691-07:00'
id: '5404409453117999568'
kind: compute#network
name: ttest
selfLink: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/ttest
subnetworks:
- https://www.googleapis.com/compute/v1/projects/myproject/regions/us-east1/subnetworks/ttest
x_gcloud_mode: custom

最测试的子网:

$ gcloud compute networks subnets describe ttest

creationTimestamp: '2016-06-27T07:25:21.649-07:00'
gatewayAddress: 10.0.0.1
id: '6237639993374575038'
ipCidrRange: 10.0.0.0/14
kind: compute#subnetwork
name: ttest
network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/ttest
region: https://www.googleapis.com/compute/v1/projects/myproject/regions/us-east1
selfLink: https://www.googleapis.com/compute/v1/projects/myproject/regions/us-east1/subnetworks/ttest

我用 --range=10.0.0.0/8 手动创建的旧网络尝试了同样的事情,然后尝试在该网络中创建集群,但似乎也不起作用。

似乎 /14 规则被硬编码到 GKE 配置的某个地方,但我真的不知道自定义网络需要什么来启动容器。

GKE 容器启动命令适用于 mode/type 为 "auto".

的任何网络

我仔细研究了所有与我相关的文档,但运气不佳。唯一突出以下摘自 this page 的片段:

The following restrictions exist when using subnetworks with other products:

  • Google Managed VMs: Supported only on auto subnetwork networks. Cannot be deployed in a custom subnet networks.

GKE 是否在后台使用托管 VM?这是导致问题的原因吗?

GKE 支持自定义子网。您遇到的问题是 GKE 强制 cluster-ipv4-cidr 范围与虚拟机可能从中分配 IP 的所有子网不相交,因为这会导致数据包在内部网络上的路由位置出现歧义。

cluster-ipv4-cidr 确定集群中的容器应使用哪些 CIDR 范围,而使用的子网确定哪些 IP 地址用于该网络中创建的所有 VM。

要解决此问题,只需停止在 gcloud 命令中指定 --cluster-ipv4-cidr 标志即可。然后 GKE 会为您选择一个安全的 cluster-ipv4-cidr 范围。