在系统自动扩缩集群时,如果删除或移动资源,则工作负载可能会暂时中断。例如,如果工作负载包含单个副本,则在删除该副本的 Pod 的当前节点时,系统可能会将此副本 Pod 重新调度到其他节点上。在 AWSNodePool 中启用集群自动扩缩器之前,请设计好工作负载以容忍潜在的中断或确保关键的 Pod 不会中断。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["# Scaling user clusters\n\nTo scale your workloads on GKE on AWS, you can configure your\nAWSNodePools to automatically scale out, or manually create and\ndelete AWSNodePools to scale up or down.\n\nCluster Autoscaler\n------------------\n\nGKE on AWS implements the Kubernetes [Cluster Autoscaler](https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler).\nWhen demand on your nodes is high, Cluster Autoscaler adds nodes to the node\npool. When demand is low, Cluster Autoscaler scales back down to a minimum size\nthat you designate. This can increase the availability of your workloads when\nyou need it while controlling costs.\n\n### Overview\n\nCluster Autoscaler automatically resizes the number of nodes in a given node\npool, based on the demands your workloads. You don't need to manually add or\nremove nodes or over-provision your node pools. Instead, you specify a minimum\nand maximum size for the node pool, and the cluster scales automatically.\n\nIf resources are deleted or moved when autoscaling your cluster, your workloads\nmight experience transient disruption. For example, if your workload consists of\na single replica, that replica's Pod might be rescheduled onto a different node\nif its current node is deleted. Before enabling Cluster Autoscaler in your\nAWSNodePool, design your workloads to tolerate potential disruption or\nensure that critical Pods are not interrupted.\n| **Note:** For autoscaling to function correctly, GKE on AWS deploys the `metrics-server` Deployment with elevated [RBAC permissions](https://kubernetes.io/docs/reference/access-authn-authz/authorization/#determine-the-request-verb) to your nodes, such as the ability to patch and update itself. Additional components, such as `coredns` and `konnectivity-agent` have specific autoscalers with permissions to scale their component up or down depending on need.\n\n### How Cluster Autoscaler Works\n\nCluster Autoscaler works on a per-node pool basis. When you create a node pool,\nyou specify a minimum and maximum size for the node pool in the\n[AWSNodePool](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/reference/node-pools)\nKubernetes resource.\n\nYou can disable Cluster Autoscaler by setting `spec.minNodeCount`\nto equal `spec.maxNodeCount` on your AWSNodePools.\n\nCluster Autoscaler increases or decreases the size of the node pool\nautomatically, based on the resource requests (rather than actual resource\nutilization) of Pods running on that node pool's nodes. It periodically checks\nthe status of Pods and nodes, and takes action:\n\nIf Pods are unschedulable because there are not enough nodes in the node pool,\nCluster Autoscaler adds nodes, up to the maximum size of the node pool. If nodes\nare under-utilized, and all Pods could be scheduled even with fewer nodes in the\nnode pool, Cluster Autoscaler removes nodes, down to the minimum size of the\nnode pool. If the node cannot be drained gracefully after a timeout period\n(10 minutes), the node is forcibly terminated. The grace period is not\nconfigurable.\n\nIf your Pods have requested too few resources (for example, if the defaults are\ninsufficient), Cluster Autoscaler does not correct the situation. You can help\nensure Cluster Autoscaler works as accurately as possible by creating adequate\nresource requests for all of your workloads.\n\n### Operating Criteria\n\nCluster Autoscaler makes the following assumptions when resizing a node pool:\n\n- All replicated Pods can be restarted on some other node, possibly causing a\n brief disruption. If your services do not tolerate disruption, we don't\n recommend using Cluster Autoscaler.\n\n- All nodes in a single node pool have the same set of labels.\n\n- If you have AWSNodePools with different instance types, Cluster\n Autoscaler considers the relative cost of launching new nodes, and attempts\n to expand the least expensive node pool.\n\n- Labels manually added after initial cluster or node pool creation are not\n tracked. Nodes created by Cluster Autoscaler are assigned labels specified\n with --node-labels at the time of node pool creation.\n\nResize a Node Pool\n------------------\n\nAn [AWSNodePool](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/reference/node-pools) includes\n`minNodeCount` and `maxNodeCount` fields. These fields declare a minimum and\nmaximum number of worker nodes in the pool. You may edit these values before or\nafter the AWSNodePool is created.\n\n### Before you begin\n\nProvision a cluster using the instructions in\n[Creating a user cluster](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/creating-user-cluster). Have the\nYAML file (for example, `cluster-0.yaml`) that creates the cluster available.\n\n### Enabling automatic node pool scaling\n\n1. From your `anthos-aws` directory, use\n `anthos-gke` to switch context to your management service.\n\n ```sh\n cd anthos-aws\n anthos-gke aws management get-credentials\n ```\n | **Note:** `anthos-gke` uses the credentials you specified when you ran `aws configure`.\n\n \u003cbr /\u003e\n\n2. To enable the Cluster Autoscaler, you edit the manifest for your\n AWSNodePool. Edit the `cluster-0.yaml` file and find the\n AWSNodePool section. Change the values for `spec.minNodeCount` and\n `spec.maxNodeCount`.\n\n The example below keeps the minimum size of this node pool at `3` nodes, but\n enables the Cluster Autoscaler to increase its size to `10` nodes. \n\n apiVersion: multicloud.cluster.gke.io/v1\n kind: AWSNodePool\n metadata:\n name: cluster-0-pool-0\n spec:\n clusterName: cluster-0\n version: 1.25.5-gke.2100\n minNodeCount: 3\n maxNodeCount: 10\n ...\n\n3. Next, apply the YAML to resize the node pool.\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl apply -f cluster-0.yaml\n\n4. The AWSNodePool resource will transition into a `Resizing` state.\n When the AWSNodePool completes scaling, it moves to the `Provisioned`\n state.\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl get AWSNodePools\n\n The output shows that the AWSNodePool is `Resizing`. Resize operations\n take several minutes to complete. \n\n NAME CLUSTER STATE AGE VERSION\n cluster-0-pool-0 cluster-0 Resizing 3h 1.25.5-gke.2100\n\nManually creating a new AWSNodePool\n-----------------------------------\n\nYou can also scale your cluster by creating new AWSNodePools.\nWhen you create a new AWSNodePool, you can also scale up or down\n[instance sizes](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/reference/instance-types).\n\n1. You can retrieve the configuration manifest of an existing AWSNodePool with\n `kubectl get`.\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl get awsnodepool cluster-0-pool-0 -o yaml \u003e new_nodepool.yaml\n\n2. Edit `new_nodepool.yaml` and remove the sections that are not present in the\n following example. Save the file.\n\n ```yaml\n apiVersion: multicloud.cluster.gke.io/v1\n kind: AWSNodePool\n metadata:\n name: NODE_POOL_NAME\n spec:\n clusterName: AWSCLUSTER_NAME\n version: CLUSTER_VERSION # latest version is 1.25.5-gke.2100\n region: AWS_REGION\n subnetID: AWS_SUBNET_ID\n minNodeCount: MINIMUM_NODE_COUNT\n maxNodeCount: MAXIMUM_NODE_COUNT\n maxPodsPerNode: MAXIMUM_PODS_PER_NODE_COUNT\n instanceType: AWS_NODE_TYPE\n keyName: KMS_KEY_PAIR_NAME\n iamInstanceProfile: NODE_IAM_PROFILE\n proxySecretName: PROXY_SECRET_NAME\n rootVolume:\n sizeGiB: ROOT_VOLUME_SIZE\n volumeType: VOLUME_TYPE # Optional\n iops: IOPS # Optional\n kmsKeyARN: NODE_VOLUME_KEY # Optional \n ```\n3. To create a new AWSNodePool, apply the manifest to your management\n cluster.\n\n env HTTPS_PROXY=http://localhost:8118 \\\n kubectl apply -f new_nodepool.yaml\n\nWhat's next\n-----------\n\nDeploy a service backed by [Ingress](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/ingress).\n\nTo see additional options, read the reference documentation on\n[AWSNodePool](/kubernetes-engine/multi-cloud/docs/aws/previous-generation/reference/node-pools)."]]