跳至內容

如何使用 eksctl 為 Amazon EKS 節點建立多個節點群組?

3 分的閱讀內容
0

我想使用 eksctl 為 Amazon Elastic Kubernetes Service (Amazon EKS) 節點建立多個節點群組。

解決方法

您可以使用 eksctl 與預設參數建立節點群組。或者,使用自訂參數與組態檔建立多個節點群組。

**注意:**若要安裝最新版本的 eksctl,請參閱 Eksctl 的安裝選項

若要確認 eksctl 已在您的本機電腦上完成設定並安裝,請開啟您偏好的終端或命令提示字元,然後執行以下命令:

eksctl version

接著,根據您要使用的參數類型,選擇以下其中一個解決方法。

使用預設參數建立節點群組

  1. 若要使用預設參數建立額外的節點群組,請執行此命令:

    eksctl create nodegroup --cluster=CLUSTER_NAME --name=NODEGROUP_NAME --region REGION_NAME

    **注意:**請將 CLUSTER_NAME 替換為您的叢集名稱,將 NODEGROUP_NAME 替換為您的節點群組名稱,並將 REGION_NAME 替換為您的 AWS 區域。

    以下為預設參數:

    Instance type = m5.largeAMI : latest AWS EKS AMI
    Nodes-desired capacity = 2
    Nodes-min capacity =2
    Nodes-max capacity=2

    **注意:**依預設,新的節點群組會從控制平面繼承 Kubernetes 的版本。您可以指定不同的 Kubernetes 版本,例如 version=1.27。若要使用最新版本的 Kubernetes,請執行 –version=latest 命令。

  2. 若要確認新的節點群組已附加至叢集,並驗證節點已加入叢集,請執行以下命令:

    kubectl get nodes
    eksctl get nodegroups --cluster CLUSTER_NAME --region REGION_NAME

    **注意:**請將 CLUSTER_NAME 替換為您的叢集名稱,並將 REGION_NAME 替換為您的 AWS 區域。

  3. 在輸出中,請確認節點群組狀態為「作用中」,且節點狀態為「就緒」。
    節點群組狀態範例:

    eksctl get nodegroups --cluster yourClusterName --region yourRegionName
    CLUSTER    NODEGROUP       STATUS  CREATED                MIN SIZE  MAX SIZE  DESIRED CAPACITY  INSTANCE TYPE  IMAGE ID     ASG NAME                      TYPE  
    clusterName example-workers ACTIVE  2023-10-28T14:30:00Z  2         2         2                 m5.large      AL2_x86_64   eks-example-workers-11223344  managed

    節點狀態範例:

    kubectl get nodes
    NAME                                          STATUS  ROLES  AGE  VERSION
    ip-192-168-100-101.us-west-2.compute.internal Ready   <none> 4h   v1.27.1-eks-1
    ip-192-168-100-102.us-west-2.compute.internal Ready   <none> 4h   v1.27.1-eks-1

使用自訂參數建立節點群組

  1. 在組態檔中定義新節點群組的參數。例如:

    kind: ClusterConfig
    apiVersion: eksctl.io/v1alpha5
    metadata:
        name: CLUSTER_NAME
        region: REGION_NAME
    nodeGroups:
      - name: NODEGROUP_NAME
        availabilityZones: ["AVAILABILITY_ZONE"]
        desiredCapacity: 3
        instanceType: m5.large
        iam:
          instanceProfileARN: "arn:aws:iam::444455556666:instance-profile/eks-nodes-base-role" #Attaching IAM role
          instanceRoleARN: "arn:aws:iam::444455556666:role/eks-nodes-base-role"
        privateNetworking: true
        securityGroups:
          withShared: true
          withLocal: true
          attachIDs: ['SECURITY_GROUP_ID']
        ssh:
          publicKeyName: 'KEY-PAIR-NAME'
        kubeletExtraConfig:
            kubeReserved:
                cpu: "300m"
                memory: "300Mi"
                ephemeral-storage: "1Gi"
            kubeReservedCgroup: "/kube-reserved"
            systemReserved:
                cpu: "300m"
                memory: "300Mi"
                ephemeral-storage: "1Gi"
        tags:
          'environment': 'development'
      - name: ng-2-builders #example of a nodegroup that uses 50% spot instances and 50% on demand instances:
        minSize: 2
        maxSize: 5
        instancesDistribution:
          maxPrice: 0.017
          instanceTypes: ["t3.small", "t3.medium"] # At least two instance types should be specified
          onDemandBaseCapacity: 0
          onDemandPercentageAboveBaseCapacity: 50
          spotInstancePools: 2
        tags:
          'environment': 'production'

    **注意:**請將 CLUSTER_NAME 替換為您的叢集名稱,將 REGION_NAME 替換為您的 AWS 區域,並將 NODEGROUP_NAME 替換為您的節點群組名稱。請將 SECURITY_GROUP_ID 替換為您的安全群組 ID,將 KEY_PAIR_NAME 替換為您的金鑰對名稱,並將 AVAILABILITY_ZONE 替換為您的可用區域。

    如需支援參數與節點群組類型的詳細資訊,請參閱 Nodegroups

  2. 若要使用組態檔建立額外的節點群組,請執行以下命令:

    eksctl create nodegroup --config-file=CONFIG_FILE

    **注意:**請將 CONFIG_FILE 替換為您的組態檔名稱。

  3. (選用) 步驟 2 中的命令會部署 AWS CloudFormation 堆疊,以建立 EKS 節點群組的資源。若要檢查堆疊狀態,請存取 CloudFormation 主控台,並確認 AWS 區域與叢集的區域相同。
    當堆疊進入 CREATE_COMPLETE 狀態後,eksctl 命令會成功結束。

  4. 若要確認新的節點群組已附加至叢集,並驗證節點已加入叢集,請執行以下命令:

    kubectl get nodes
    eksctl get nodegroups --cluster CLUSTER_NAME --region REGION_NAME

    **注意:**請將 CLUSTER_NAME 替換為您的叢集名稱,並將 REGION_NAME 替換為您的 AWS 區域。

    在輸出中,請確認節點群組狀態為「作用中」,且節點狀態為「就緒」。

    節點群組狀態範例:

    eksctl get nodegroups --cluster yourClusterName --region yourRegionName
    CLUSTER    NODEGROUP       STATUS  CREATED                MIN SIZE  MAX SIZE  DESIRED CAPACITY  INSTANCE TYPE  IMAGE ID     ASG NAME                      TYPE  
    clusterName example-workers ACTIVE  2023-10-28T14:30:00Z  2         2         3                 m5.large      AL2_x86_64   eks-example-workers-11223344  managed

    節點狀態範例:

    kubectl get nodes
    NAME                                          STATUS  ROLES  AGE  VERSION
    ip-192-168-100-101.us-west-2.compute.internal Ready   <none> 4h   v1.27.1-eks-1
    ip-192-168-100-102.us-west-2.compute.internal Ready   <none> 4h   v1.27.1-eks-1
    ip-192-168-100-103.us-west-2.compute.internal Ready   <none> 4h   v1.27.1-eks-1