

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

# EKS 受管節點群組
<a name="nodegroup-managed"></a>

 [Amazon EKS 受管節點群組](https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html)是一項功能，可自動化 Amazon EKS Kubernetes 叢集節點 (EC2 執行個體） 的佈建和生命週期管理。客戶可以為其叢集佈建最佳化的節點群組，EKS 會將其節點保持在最新的 Kubernetes 和主機作業系統版本。

EKS 受管節點群組是自動擴展群組和相關聯的 EC2 執行個體，由 Amazon EKS 叢集的 AWS 管理。每個節點群組使用 Amazon EKS 最佳化的 Amazon Linux 2 AMI。Amazon EKS 可讓您輕鬆將錯誤修正和安全性修補程式套用至節點，並將它們更新至最新的 Kubernetes 版本。每個節點群組都會為您的叢集啟動自動擴展群組，可以跨越多個 AWS VPC 可用區域和子網路，以提供高可用性。

 受管節點群組**的新**啟動範本支援 [受管節點群組的啟動範本支援](launch-template-support.md) 

**注意**  
「未受管節點群組」一詞已用於參考 eksctl 從一開始就支援的節點群組 （透過 `nodeGroups` 欄位表示）。`ClusterConfig` 檔案會繼續使用 `nodeGroups` 欄位來定義未受管節點群組，並使用 `managedNodeGroups` 欄位定義受管節點群組。

## 建立受管節點群組
<a name="_creating_managed_nodegroups"></a>

```
$ eksctl create nodegroup
```

### 新叢集
<a name="_new_clusters"></a>

若要使用受管節點群組建立新的叢集，請執行

```
eksctl create cluster
```

若要建立多個受管節點群組並對組態有更多控制權，可以使用組態檔案。

**注意**  
受管節點群組與未受管節點群組沒有完整的功能同位。

```
# cluster.yaml
# A cluster with two managed nodegroups
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: managed-cluster
  region: us-west-2

managedNodeGroups:
  - name: managed-ng-1
    minSize: 2
    maxSize: 4
    desiredCapacity: 3
    volumeSize: 20
    ssh:
      allow: true
      publicKeyPath: ~/.ssh/ec2_id_rsa.pub
      # new feature for restricting SSH access to certain AWS security group IDs
      sourceSecurityGroupIds: ["sg-00241fbb12c607007"]
    labels: {role: worker}
    tags:
      nodegroup-role: worker
    iam:
      withAddonPolicies:
        externalDNS: true
        certManager: true

  - name: managed-ng-2
    instanceType: t2.large
    minSize: 2
    maxSize: 3
```

您可以[在這裡](https://github.com/eksctl-io/eksctl/blob/main/examples/15-managed-nodes.yaml)找到另一個用於建立受管節點群組的組態檔案範例。

您可以擁有同時具有受管和未受管節點群組的叢集。未受管節點群組不會在 AWS EKS 主控台中顯示，但`eksctl get nodegroup`會列出這兩種類型的節點群組。

```
# cluster.yaml
# A cluster with an unmanaged nodegroup and two managed nodegroups.
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: managed-cluster
  region: us-west-2

nodeGroups:
  - name: ng-1
    minSize: 2

managedNodeGroups:
  - name: managed-ng-1
    minSize: 2
    maxSize: 4
    desiredCapacity: 3
    volumeSize: 20
    ssh:
      allow: true
      publicKeyPath: ~/.ssh/ec2_id_rsa.pub
      # new feature for restricting SSH access to certain AWS security group IDs
      sourceSecurityGroupIds: ["sg-00241fbb12c607007"]
    labels: {role: worker}
    tags:
      nodegroup-role: worker
    iam:
      withAddonPolicies:
        externalDNS: true
        certManager: true

  - name: managed-ng-2
    instanceType: t2.large
    privateNetworking: true
    minSize: 2
    maxSize: 3
```

 **全新**支援自訂 AMI、安全群組、`instancePrefix`、`instanceName`、`ebsOptimized``volumeType`、`volumeName`、`volumeEncrypted`、`volumeKmsKeyID`、、`volumeIOPS`、`maxPodsPerNode`、 `preBootstrapCommands``overrideBootstrapCommand`和 `disableIMDSv1` 

```
# cluster.yaml
# A cluster with a managed nodegroup with customization.
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: managed-cluster
  region: us-west-2

managedNodeGroups:
  - name: custom-ng
    ami: ami-0e124de4755b2734d
    securityGroups:
      attachIDs: ["sg-1234"]
    maxPodsPerNode: 80
    ssh:
      allow: true
    volumeSize: 100
    volumeName: /dev/xvda
    volumeEncrypted: true
    # defaults to true, which enforces the use of IMDSv2 tokens
    disableIMDSv1: false
    overrideBootstrapCommand: |
      #!/bin/bash
      /etc/eks/bootstrap.sh managed-cluster --kubelet-extra-args '--node-labels=eks.amazonaws.com/nodegroup=custom-ng,eks.amazonaws.com/nodegroup-image=ami-0e124de4755b2734d'
```

如果您請求的執行個體類型僅適用於一個區域 （且 eksctl 組態需要兩個 的規格），請務必將可用區域新增至節點群組請求：

```
# cluster.yaml
# A cluster with a managed nodegroup with "availabilityZones"
---

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: flux-cluster
  region: us-east-2
  version: "1.23"

availabilityZones: ["us-east-2b", "us-east-2c"]
managedNodeGroups:
  - name: workers
    instanceType: hpc6a.48xlarge
    minSize: 64
    maxSize: 64
    labels: { "fluxoperator": "true" }
    availabilityZones: ["us-east-2b"]
    efaEnabled: true
    placement:
      groupName: eks-efa-testing
```

對於僅在一個區域中可用的 [ Hpc6 系列](https://aws.amazon.com/ec2/instance-types/hpc6/)等執行個體類型而言，這可能是如此。

### 現有叢集
<a name="_existing_clusters"></a>

```
eksctl create nodegroup --managed
```

秘訣：如果您使用 `ClusterConfig` 檔案來描述整個叢集，請在 `managedNodeGroups` 欄位中描述新的受管節點群組並執行：

```
eksctl create nodegroup --config-file=YOUR_CLUSTER.yaml
```

## 升級受管節點群組
<a name="_upgrading_managed_nodegroups"></a>

您可以隨時將節點群組更新為您正在使用的 AMI 類型的最新 EKS 最佳化 AMI 發行版本。

如果您的節點群組與叢集的 Kubernetes 版本相同，您可以更新到您正在使用的 AMI 類型之 Kubernetes 版本的最新 AMI 發行版本。如果您的節點群組是叢集 Kubernetes 版本的先前 Kubernetes 版本，您可以將節點群組更新為符合節點群組 Kubernetes 版本的最新 AMI 發行版本，或更新為符合叢集 Kubernetes 版本的最新 AMI 發行版本。您無法將節點群組復原至較早的 Kubernetes 版本。

若要將受管節點群組升級至最新的 AMI 發行版本：

```
eksctl upgrade nodegroup --name=managed-ng-1 --cluster=managed-cluster
```

您可以使用下列方式，將節點群組升級至指定 Kubernetes 版本的最新 AMI 版本：

```
eksctl upgrade nodegroup --name=managed-ng-1 --cluster=managed-cluster --kubernetes-version=<kubernetes-version>
```

若要升級至特定 AMI 發行版本，而非最新版本，請傳遞 `--release-version`：

```
eksctl upgrade nodegroup --name=managed-ng-1 --cluster=managed-cluster --release-version=1.19.6-20210310
```

**注意**  
如果使用自訂 AMIs 部署受管節點，必須遵循下列工作流程來部署新版本的自訂 AMI。
+ 節點群組的初始部署必須使用啟動範本完成，例如

  ```
  managedNodeGroups:
    - name: launch-template-ng
      launchTemplate:
        id: lt-1234
        version: "2" #optional (uses the default version of the launch template if unspecified)
  ```
+ 建立新的自訂 AMI 版本 （使用 AWS EKS 主控台）。
+ 使用新的 AMI ID 建立新的啟動範本版本 （使用 AWS EKS 主控台）。
+ 將節點升級至新版本的啟動範本，例如

  ```
  eksctl upgrade nodegroup --name nodegroup-name --cluster cluster-name --launch-template-version new-template-version
  ```

## 處理節點的平行升級
<a name="_handling_parallel_upgrades_for_nodes"></a>

多個受管節點可以同時升級。若要設定平行升級，請在建立節點群組時定義節點群組`updateConfig`的 。您可以在[此處](https://github.com/eksctl-io/eksctl/blob/main/examples/15-managed-nodes.yaml)`updateConfig`找到範例。

若要避免因一次升級多個節點而導致工作負載停機，您可以在 的 `maxUnavailable` 欄位中指定此節點，藉此限制升級期間無法使用的節點數目`updateConfig`。或者，使用 `maxUnavailablePercentage`，將無法使用節點的最大數量定義為節點總數的百分比。

請注意， `maxUnavailable`不能高於 `maxSize`。此外， `maxUnavailable`和 `maxUnavailablePercentage`無法同時使用。

此功能僅適用於受管節點。

## 更新受管節點群組
<a name="_updating_managed_nodegroups"></a>

 `eksctl` 允許更新受管節點群組的 [UpdateConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-eks-nodegroup-updateconfig.html) 區段。本節定義兩個欄位： `MaxUnavailable`和 `MaxUnavailablePercentage`。您的節點群組在更新期間不會受到影響，因此不應預期停機時間。

命令`update nodegroup`應與使用 `--config-file`旗標的組態檔案搭配使用。節點群組應包含 `nodeGroup.updateConfig`區段。如需詳細資訊，請參閱[此處](https://geoffcline.github.io/eksctl-schema-demo/#nodeGroups-updateConfig)。

## 節點群組運作狀態問題
<a name="_nodegroup_health_issues"></a>

EKS 受管節點群組會自動檢查節點群組和節點的組態是否有運作狀態問題，並透過 EKS API 和主控台進行報告。若要檢視節點群組的運作狀態問題：

```
eksctl utils nodegroup-health --name=managed-ng-1 --cluster=managed-cluster
```

## 管理標籤
<a name="_managing_labels"></a>

EKS 受管節點群組支援連接套用至節點群組中 Kubernetes 節點的標籤。這是在叢集或節點群組建立期間，透過 eksctl 中的 `labels` 欄位指定。

若要在節點群組上設定新標籤或更新現有標籤：

```
eksctl set labels --cluster managed-cluster --nodegroup managed-ng-1 --labels kubernetes.io/managed-by=eks,kubernetes.io/role=worker
```

若要從節點群組取消設定或移除標籤：

```
eksctl unset labels --cluster managed-cluster --nodegroup managed-ng-1 --labels kubernetes.io/managed-by,kubernetes.io/role
```

若要檢視節點群組上設定的所有標籤：

```
eksctl get labels --cluster managed-cluster --nodegroup managed-ng-1
```

## 擴展受管節點群組
<a name="_scaling_managed_nodegroups"></a>

 `eksctl scale nodegroup` 也支援受管節點群組。擴展受管或未受管節點群組的語法相同。

```
eksctl scale nodegroup --name=managed-ng-1 --cluster=managed-cluster --nodes=4 --nodes-min=3 --nodes-max=5
```

## 詳細資訊
<a name="_further_information"></a>
+  [EKS 受管節點群組](https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html) 