我想使用 eksctl 為 Amazon Elastic Kubernetes Service (Amazon EKS) 節點建立多個節點群組。
簡短描述
您可以使用 eksctl 透過預設參數建立節點群組,或使用多個節點群組的組態檔案搭配自訂參數來建立節點群組。
解決方法
使用預設參數建立節點群組
1. 安裝 eksctl。
2. 若要確認是否已在終端上安裝 eksctl 並設定正確權限,請執行此命令:
$ eksctl version
3. 若要使用預設參數建立其他節點群組,請執行此命令:
$ eksctl create nodegroup --cluster=yourClusterName --name=yourNodeGroupName --region yourRegionName
預設參數如下:
Instance type = m5.large
AMI : lastest AWS EKS AMI
Nodes-desired capacity = 2
Nodes-min capacity =2
Nodes-max capacity=2
注意:預設情況下,新節點群組會繼承從控制平面安裝的 Kubernetes 版本 (–version=auto),但您可以指定其他版本的 Kubernetes (例如,version=1.13)。若要使用最新版本的 Kubernetes,請執行 –version=latest 命令。
4. 開啟 AWS CloudFormation 主控台,並選擇與您建立的節點群組相關聯的堆疊。然後,選擇事件索引標籤,查看顯示您的堆疊已部署的 AWS CloudFormation 事件。
5. 若要確認新的節點群組是否已連接至叢集,並驗證是否已套用節點群組組態,請執行以下命令:
$ Kubectl get nodes
$ eksctl get nodegroups --cluster yourClusterName
使用自訂參數建立節點群組
1. 在組態檔案中定義新節點群組的參數。例如:
kind: ClusterConfig
apiVersion: eksctl.io/v1alpha5
metadata:
name: yourClusterName
region: yourRegionName
nodeGroups:
- name: ng1-Workers
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'
2. 若要使用組態檔建立其他節點群組,請執行以下命令:
$ eksctl create nodegroup --config-file= yourConfigFileName
3. 開啟 AWS CloudFormation 主控台,然後選擇與您建立的節點群組相關聯的堆疊。然後,選擇事件索引標籤,查看顯示您的堆疊已部署的 AWS CloudFormation 事件。
4. 若要確認新的節點群組是否已連接至叢集,並驗證是否已套用節點群組組態,請執行以下命令:
$ kubectl get nodes
$ eksctl get nodegroups --cluster yourClusterName
您會看到您的節點已加入該叢集。您可以透過使用 eksctl 看到這兩個節點群組是可見的。