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

2 分的閱讀內容
0

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

簡短說明

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

若要安裝最新版本的 eksctl,請參閱 eksctl 網站上的安裝

若要確認是否已在終端上安裝 eksctl 並設定正確許可,請執行下列命令:

$ eksctl version

然後根據您要使用的參數類型選擇以下其中一種解決方法。

解決方法

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

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

    $ eksctl create nodegroup --cluster=yourClusterName --name=yourNodeGroupName --region yourRegionName
  2. 以下是預設參數:

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

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

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

    $ kubectl get nodes
    $ eksctl get nodegroups --cluster yourClusterName --region yourRegionName

    在輸出中,請確認節點的狀態為 READY,且節點群組狀態為 ACTIVE。例如:

    節點群組狀態

    $ 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  ngWorkers  ACTIVE  Date&Time    *        *              *             m5.large      AL2_x86_64   ASGNAME   managed
    

    ****節點狀態


    $ kubectl get nodes
    
    NAME                                    STATUS ROLES AGE VERSION         
    ip-***-**-**-***.region.compute.internal Ready <none> 4h v1.2x.x-eks-xx  
    ip-***-**-***-**.region.compute.internal Ready <none> 4h v1.2x.x-eks-xx
    
    Create a node group with custom parameters
    
    

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

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

    kind: ClusterConfig
    apiVersion: eksctl.io/v1alpha5
    metadata:
        name: clusterName
        region: region
    nodeGroups:
      - name: ngWorkers
        availabilityZones: ["az-name"]
        desiredCapacity: 3
        instanceType: m5.large
        iam:
          instanceProfileARN: "arn:aws:iam::11111:instance-profile/eks-nodes-base-role" #Attaching IAM role
          instanceRoleARN: "arn:aws:iam::1111:role/eks-nodes-base-role"
        privateNetworking: true
        securityGroups:
          withShared: true
          withLocal: true
          attachIDs: ['sg-11111', 'sg-11112']
        ssh:
          publicKeyName: 'my-instance-key'
        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'

    如需支援的參數和節點群組類型的詳細資訊,請參閱 eksctl 網站上的節點群組

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

    $ eksctl create nodegroup --config-file=yourConfigFileName
  3. (選擇性) 步驟 2 中的命令會部署 AWS CloudFormation 堆疊,以建立 EKS 節點群組的資源。若要檢查堆疊狀態,請存取 CloudFormation 主控台並確認 AWS 區域與叢集相同。 
    堆疊處於 CREATE_COMPLETE 狀態之後,eksctl 命令會成功結束。

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

    $ kubectl get nodes
    $ eksctl get nodegroups --cluster yourClusterName --region yourRegionName

    在輸出中,請確認節點的狀態為 READY,且節點群組狀態為 ACTIVE。例如:
    節點群組狀態

    $ 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  ngWorkers  ACTIVE  Date&Time    *        *              *             m5.large      AL2_x86_64   ASGNAME   managed

    **節點狀態 **

    $ kubectl get nodes
    
    NAME                                    STATUS ROLES AGE VERSION         
    ip-***-**-**-***.region.compute.internal Ready <none> 4h v1.2x.x-eks-xx  
    ip-***-**-***-**.region.compute.internal Ready <none> 4h v1.2x.x-eks-xx
AWS 官方
AWS 官方已更新 1 年前