为什么在我创建命名空间时我的 GKE 集群会升级?

Why is my GKE cluster upscaling when I create a namespace?

我正在观察 GKE 中新创建的集群的奇怪行为。 创建后,有一个节点。当我创建我的第一个命名空间时,它会自动扩展到 2 个节点,尽管第一个节点上的资源仍然很低。造成这种情况的原因是什么以及防止它的方法? 我使用以下定义创建了集群(使用 python API):

            cluster={
                "name": "mycluster",
                "initial_cluster_version": "latest",
                "network_policy": {
                    "enabled": True,
                    "provider": "PROVIDER_UNSPECIFIED"
                },
                "node_pools": [
                    {
                        "name": "default",
                        "autoscaling": {
                            "enabled": True,
                            "max_node_count": 5,
                            "min_node_count": 1
                        },
                        "config": {
                            "image_type": "UBUNTU",
                            "machine_type": "n1-standard-4",
                            "oauth_scopes": [
                                # Allows pulling images from GCR
                                "https://www.googleapis.com/auth/devstorage.read_only",

                                # Needed for monitoring
                                "https://www.googleapis.com/auth/logging.write",
                                "https://www.googleapis.com/auth/monitoring"
                            ]
                        },
                        "initial_node_count": 1
                    }
                ]
            },

TL;DR

创建命名空间时您的集群没有纵向扩展。

原因如下:

Limitations and requirements

Your cluster must have at least 2 nodes of type n1-standard-1 or higher. The recommended minimum size cluster to run network policy enforcement is 3 n1-standard-1 instances.

Cloud.google.com: Kubernetes Engine: Network Policy: Limitations and requirements

您创建初始节点数为 1GKE 集群这一事实导致 calico-typha-XXXscale-up 发送请求集群最小 2 个节点。


假设如下:

  • GKE 集群,发布渠道为 Regular
  • 启用自动缩放:
    • 初始节点数:1 个节点
    • 最少:1 个节点
    • 最多:3 个节点
  • 节点机器类型:n1-standard-1 或更高
  • 已启用网络策略。

当您根据上述要求创建集群时,您将获得一个具有 1 个节点的集群。一旦 calico-typha-XXX-XXX 检测到节点数量小于 2 并向 scale-up 发送请求,这就会改变。

您可以通过发出命令来获取有关此的更详细的日志:

  • $ kubectl get pods -A
  • $ kubectl describe pod -n kube-system calico-typha-XXX-XXX

您应该得到与此类似的输出部分:

  Normal   TriggeredScaleUp  18m   cluster-autoscaler                              pod triggered scale-up: [{https://content.googleapis.com/compute/v1/projects/REDACTED/zones/europe-west3-c/instanceGroups/gke-ubuntu-grp 1->2 (max: 3)}]

您还可以查看 Kubernetes 事件日志:

  • kubectl get events -A

请记住,参数 -A 会导致输出更多有价值的信息,例如:

kube-system   3m6s        Normal    TriggeredScaleUp          pod/calico-typha-6b8d44c954-7s9zx                                pod triggered scale-up: [{https://content.googleapis.com/compute/v1/projects/REDACTED/zones/europe-west3-c/instanceGroups/gke-ubuntu-grp 1->2 (max: 3)}]

请查看其他文档: