我想使用 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 控制台,然后选择与您创建的节点组关联的堆栈。然后选择 Events(事件)选项卡,查看显示您的堆栈已部署的 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 看到这两个节点组是可见的。