使用節點群組 - Eksctl 使用者指南

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用節點群組

建立節點群組

除了與叢集一起建立的初始節點群組之外,您還可以新增一或多個節點群組。

若要建立其他節點群組,請使用:

eksctl create nodegroup --cluster=<clusterName> [--name=<nodegroupName>]
注意

--version 受管節點群組不支援 flag。它一律會從控制平面繼承版本。

根據預設,新的未受管節點群組會從控制平面 (--version=auto) 繼承版本,但您可以指定不同的版本,您也可以使用 --version=latest強制使用最新版本。

此外,您可以使用與 相同的組態檔案eksctl create cluster

eksctl create nodegroup --config-file=<path>

從組態檔案建立節點群組

節點群組也可以透過叢集定義或組態檔案建立。根據下列範例組態檔案和名為 的現有叢集dev-cluster

# dev-cluster.yaml apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: dev-cluster region: eu-north-1 managedNodeGroups: - name: ng-1-workers labels: { role: workers } instanceType: m5.xlarge desiredCapacity: 10 volumeSize: 80 privateNetworking: true - name: ng-2-builders labels: { role: builders } instanceType: m5.2xlarge desiredCapacity: 2 volumeSize: 100 privateNetworking: true

節點群組 ng-1-workersng-2-builders可以使用此命令建立:

eksctl create nodegroup --config-file=dev-cluster.yaml

負載平衡

如果您已經準備好將現有的傳統負載平衡器或/和目標群組連接到節點群組,您可以在組態檔案中指定這些群組。建立節點群組時,傳統負載平衡器或/和目標群組會自動與 ASG 建立關聯。這僅支援透過 nodeGroups 欄位定義的自我管理節點群組。

# dev-cluster-with-lb.yaml apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: dev-cluster region: eu-north-1 nodeGroups: - name: ng-1-web labels: { role: web } instanceType: m5.xlarge desiredCapacity: 10 privateNetworking: true classicLoadBalancerNames: - dev-clb-1 - dev-clb-2 asgMetricsCollection: - granularity: 1Minute metrics: - GroupMinSize - GroupMaxSize - GroupDesiredCapacity - GroupInServiceInstances - GroupPendingInstances - GroupStandbyInstances - GroupTerminatingInstances - GroupTotalInstances - name: ng-2-api labels: { role: api } instanceType: m5.2xlarge desiredCapacity: 2 privateNetworking: true targetGroupARNs: - arn:aws:elasticloadbalancing:eu-north-1:01234567890:targetgroup/dev-target-group-1/abcdef0123456789

組態檔案中的節點群組選擇

若要僅對組態檔案中指定的節點群組子集執行 createdelete操作,有兩個接受 glob 清單的 CLI 旗標,–0—以及 –1—,例如:

eksctl create nodegroup --config-file=<path> --include='ng-prod-*-??' --exclude='ng-test-1-ml-a,ng-test-2-?'

使用上面的範例組態檔案,可以建立工作者節點群組,但工作者節點群組除外,使用下列命令:

eksctl create nodegroup --config-file=dev-cluster.yaml --exclude=ng-1-workers

或者,也可以使用下列方式刪除建置器節點群組:

eksctl delete nodegroup --config-file=dev-cluster.yaml --include=ng-2-builders --approve

在這種情況下,我們也需要提供 --approve命令,才能實際刪除節點群組。

包含和排除規則

  • 如果未指定 --include--exclude ,則會包含所有項目

  • 如果只指定 --include ,則只會包含符合這些 glob 的節點群組

  • 如果只指定 --exclude ,則會包含不符合這些 glob 的所有節點群組

  • 如果指定兩者,則--exclude規則優先於 --include(即兩個群組中符合規則的節點群組將被排除)

列出節點群組

若要列出節點群組或所有節點群組的詳細資訊,請使用:

eksctl get nodegroup --cluster=<clusterName> [--name=<nodegroupName>]

若要以 YAML 或 JSON 格式列出一或多個節點群組,其會輸出比預設日誌資料表更多的資訊,請使用:

# YAML format eksctl get nodegroup --cluster=<clusterName> [--name=<nodegroupName>] --output=yaml # JSON format eksctl get nodegroup --cluster=<clusterName> [--name=<nodegroupName>] --output=json

節點群組不可變性

根據設計,節點群組是不可變的。這表示如果您需要變更某些項目 (擴展除外),例如 AMI 或節點群組的執行個體類型,則需要使用所需的變更建立新的節點群組、移動負載並刪除舊的節點群組。請參閱刪除和耗盡節點群組一節。

擴展節點群組

Nodegroup 擴展是一個可能需要幾分鐘的程序。未指定--wait旗標時,eksctl樂觀地預期節點群組會進行擴展,並在傳送 AWS API 請求後立即傳回。若要讓 eksctl 等待節點可用,請新增如下所示的--wait旗標。

注意

向下/向內擴展節點群組 (即減少節點數量) 可能會導致錯誤,因為我們完全依賴 ASG 的變更。這表示移除/終止的節點 (未明確耗盡)。這可能是未來需要改進的領域。

直接呼叫更新受管節點群組組態的 EKS API,即可擴展受管節點群組。

擴展單一節點群組

您可以使用 eksctl scale nodegroup命令來擴展節點群組:

eksctl scale nodegroup --cluster=<clusterName> --nodes=<desiredCount> --name=<nodegroupName> [ --nodes-min=<minSize> ] [ --nodes-max=<maxSize> ] --wait

例如,若要將 ng-a345f4e1中的節點群組擴展cluster-1至 5 個節點,請執行:

eksctl scale nodegroup --cluster=cluster-1 --nodes=5 ng-a345f4e1

也可以使用傳遞至 的組態檔案來擴展節點群組,--config-file並指定應使用 擴展的節點群組名稱--name。Eksctl 將搜尋組態檔案,並探索該節點群組及其擴展組態值。

如果所需的節點數量NOT在目前最小和目前最大數量節點的範圍內,則會顯示一個特定錯誤。這些值也可以--nodes-max分別與旗標 --nodes-min和 一起傳遞。

擴展多個節點群組

Eksctl 可以探索和擴展使用 傳遞的組態檔案中找到的所有節點群組--config-file

與擴展單一節點群組類似,相同的一組驗證也適用於每個節點群組。例如,所需的節點數量必須在節點數量下限和上限的範圍內。

刪除和耗盡節點群組

若要刪除節點群組,請執行:

eksctl delete nodegroup --cluster=<clusterName> --name=<nodegroupName>

包含和排除規則也可以與此命令搭配使用。

注意

這將在刪除執行個體之前耗盡該節點群組中的所有 Pod。

若要在耗盡過程中略過移出規則,請執行:

eksctl delete nodegroup --cluster=<clusterName> --name=<nodegroupName> --disable-eviction

所有節點都會封鎖,且所有 Pod 都會在刪除時從節點群組移出,但如果您需要耗盡節點群組而不將其刪除,請執行:

eksctl drain nodegroup --cluster=<clusterName> --name=<nodegroupName>

若要取消協調節點群組,請執行:

eksctl drain nodegroup --cluster=<clusterName> --name=<nodegroupName> --undo

若要忽略移出規則,例如 PodDisruptionBudget 設定,請執行:

eksctl drain nodegroup --cluster=<clusterName> --name=<nodegroupName> --disable-eviction

若要加速耗盡程序,您可以--parallel <value>為要平行耗盡的節點數量指定 。

其他功能

您也可以為節點群組啟用 SSH、ASG 存取和其他功能,例如:

eksctl create nodegroup --cluster=cluster-1 --node-labels="autoscaling=enabled,purpose=ci-worker" --asg-access --full-ecr-access --ssh-access

更新標籤

中沒有特定命令eksctl可更新節點群組的標籤,但可以使用 輕鬆達成kubectl,例如:

kubectl label nodes -l alpha.eksctl.io/nodegroup-name=ng-1 new-label=foo

SSH 存取

您可以在節點群組組態publicKeyPath中設定其中一個 publicKeyNamepublicKey,以啟用節點群組的 SSH 存取。或者,您可以使用 AWS Systems Manager (SSM) 在節點上 SSH,方法是使用 設定節點群組enableSsm

managedNodeGroups: - name: ng-1 instanceType: m5.large desiredCapacity: 1 ssh: # import public key from file publicKeyPath: ~/.ssh/id_rsa_tests.pub - name: ng-2 instanceType: m5.large desiredCapacity: 1 ssh: # use existing EC2 key publicKeyName: ec2_dev_key - name: ng-3 instanceType: m5.large desiredCapacity: 1 ssh: # import inline public key publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqZEdzvHnK/GVP8nLngRHu/GDi/3PeES7+Bx6l3koXn/Oi/UmM9/jcW5XGziZ/oe1cPJ777eZV7muEvXg5ZMQBrYxUtYCdvd8Rt6DIoSqDLsIPqbuuNlQoBHq/PU2IjpWnp/wrJQXMk94IIrGjY8QHfCnpuMENCucVaifgAhwyeyuO5KiqUmD8E0RmcsotHKBV9X8H5eqLXd8zMQaPl+Ub7j5PG+9KftQu0F/QhdFvpSLsHaxvBzA5nhIltjkaFcwGQnD1rpCM3+UnQE7Izoa5Yt1xoUWRwnF+L2TKovW7+bYQ1kxsuuiX149jXTCJDVjkYCqi7HkrXYqcC1sbsror someuser@hostname" - name: ng-4 instanceType: m5.large desiredCapacity: 1 ssh: # enable SSH using SSM enableSsm: true