本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用节点组
创建节点组
除了与集群一起创建的初始节点组外,您还可以添加一个或多个节点组。
要创建额外的节点组,请使用:
eksctl create nodegroup --cluster=<clusterName> [--name=<nodegroupName>]
注意
--version托管节点组不支持标志。它总是继承控制平面的版本。
默认情况下,新的非托管节点组继承控制平面 (--version=auto) 的版本,但您可以指定其他版本,也可以使用--version=latest强制使用最新版本。
此外,您可以使用相同的配置文件用于eksctl create cluster:
eksctl create nodegroup --config-file=<path>
从配置文件创建节点组
也可以通过集群定义或配置文件创建节点组。假设以下示例配置文件和一个名为的现有集群dev-cluster:
# dev-cluster.yaml apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: dev-cluster region: eu-north-1 managedNodeGroups: - name: ng-1-workers labels: { role: workers } instanceType: m5.xlarge desiredCapacity: 10 volumeSize: 80 privateNetworking: true - name: ng-2-builders labels: { role: builders } instanceType: m5.2xlarge desiredCapacity: 2 volumeSize: 100 privateNetworking: true
ng-2-builders可以使用以下命令创建节点组ng-1-workers和:
eksctl create nodegroup --config-file=dev-cluster.yaml
负载均衡
如果您已经准备好将现有的经典负载均衡器 or/and 目标组附加到节点组,则可以在配置文件中指定这些目标组。创建节点组时,经典负载均衡器 or/and 目标组会自动与 ASG 关联。仅支持通过该字段定义的自管理节点组。nodeGroups
# dev-cluster-with-lb.yaml apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: dev-cluster region: eu-north-1 nodeGroups: - name: ng-1-web labels: { role: web } instanceType: m5.xlarge desiredCapacity: 10 privateNetworking: true classicLoadBalancerNames: - dev-clb-1 - dev-clb-2 asgMetricsCollection: - granularity: 1Minute metrics: - GroupMinSize - GroupMaxSize - GroupDesiredCapacity - GroupInServiceInstances - GroupPendingInstances - GroupStandbyInstances - GroupTerminatingInstances - GroupTotalInstances - name: ng-2-api labels: { role: api } instanceType: m5.2xlarge desiredCapacity: 2 privateNetworking: true targetGroupARNs: - arn:aws:elasticloadbalancing:eu-north-1:01234567890:targetgroup/dev-target-group-1/abcdef0123456789
在配置文件中选择节点组
要仅对配置文件中指定的节点组的子集执行create或delete操作,有两个 CLI 标志接受全局列表,0—例如:1—
eksctl create nodegroup --config-file=<path> --include='ng-prod-*-??' --exclude='ng-test-1-ml-a,ng-test-2-?'
使用上面的示例配置文件,可以使用以下命令创建除工作节点组之外的所有工作节点组:
eksctl create nodegroup --config-file=dev-cluster.yaml --exclude=ng-1-workers
或者可以使用以下方法删除生成器节点组:
eksctl delete nodegroup --config-file=dev-cluster.yaml --include=ng-2-builders --approve
在这种情况下,我们还需要提供--approve命令来实际删除节点组。
包含和排除规则
-
如果未指定
--include或--exclude,则将所有内容都包括在内 -
如果仅指定,
--include则仅包含与这些 glob 匹配的节点组 -
如果仅指定,
--exclude则将包括所有与这些全局不匹配的节点组 -
如果两者都指定,则
--exclude规则优先于--include(即将排除与两个组中规则匹配的节点组)
列出节点组
要列出有关节点组或所有节点组的详细信息,请使用:
eksctl get nodegroup --cluster=<clusterName> [--name=<nodegroupName>]
要以 YAML 或 JSON 格式列出一个或多个节点组,这些节点组输出的信息比默认日志表还要多,请使用:
# YAML format eksctl get nodegroup --cluster=<clusterName> [--name=<nodegroupName>] --output=yaml # JSON format eksctl get nodegroup --cluster=<clusterName> [--name=<nodegroupName>] --output=json
节点组不变性
根据设计,节点组是不可变的。这意味着,如果您需要更改诸如 AMI 或节点组的实例类型之类的内容(扩展除外),则需要创建一个具有所需更改的新节点组,移动负载并删除旧的节点组。请参阅删除和清空节点组部分。
扩展节点组
节点组扩展是一个最多可能需要几分钟的过程。如果未指定--wait标志,eksctl乐观地期望节点组能够扩展,并在发送 AWS API 请求后立即返回。要eksctl等到节点可用,请添加一个--wait标志,如下例所示。
注意
扩展节点组 down/in (即减少节点数量)可能会导致错误,因为我们完全依赖于 ASG 的更改。这意味着被清空的节点并 removed/terminated 未被明确排空。这可能是将来需要改进的领域。
扩展托管节点组是通过直接调用更新托管节点组配置的 EKS API 来实现的。
扩展单个节点组
可以使用以下命令来缩放节点组:eksctl scale nodegroup
eksctl scale nodegroup --cluster=<clusterName> --nodes=<desiredCount> --name=<nodegroupName> [ --nodes-min=<minSize> ] [ --nodes-max=<maxSize> ] --wait
例如,要将节点组ng-a345f4e1扩展cluster-1到 5 个节点,请运行:
eksctl scale nodegroup --cluster=cluster-1 --nodes=5 ng-a345f4e1
也可以使用传递给的配置文件--config-file并指定应缩放的节点组的名称来缩放节点组。--nameEksctl 将搜索配置文件并发现该节点组及其扩展配置值。
如果所需的节点数在当前最小和当前最大节点数的范围NOT内,则会显示一个特定的错误。这些值也可以--nodes-max分别使用标志--nodes-min和传递。
扩展多个节点组
Eksctl 可以发现和扩展在随附的配置文件中找到的所有节点组。--config-file
与扩展单个节点组类似,相同的验证集适用于每个节点组。例如,所需的节点数必须在最小和最大节点数的范围内。
删除和清空节点组
要删除节点组,请运行:
eksctl delete nodegroup --cluster=<clusterName> --name=<nodegroupName>
包含和排除规则也可以与此命令一起使用。
注意
这将在删除实例之前耗尽该节点组中的所有 pod。
要在排空过程中跳过驱逐规则,请运行:
eksctl delete nodegroup --cluster=<clusterName> --name=<nodegroupName> --disable-eviction
所有节点都被封锁,所有的 pod 在删除时都会被逐出节点组,但是如果你需要在不删除节点组的情况下排空节点,请运行:
eksctl drain nodegroup --cluster=<clusterName> --name=<nodegroupName>
要解除对节点组的封锁,请运行:
eksctl drain nodegroup --cluster=<clusterName> --name=<nodegroupName> --undo
要忽略诸如 PodDisruptionBudget 设置之类的驱逐规则,请运行:
eksctl drain nodegroup --cluster=<clusterName> --name=<nodegroupName> --disable-eviction
为了加快排空过程,您可以指定要--parallel <value>并行排空的节点数。
其他功能
您还可以为节点组启用 SSH、ASG 访问和其他功能,例如:
eksctl create nodegroup --cluster=cluster-1 --node-labels="autoscaling=enabled,purpose=ci-worker" --asg-access --full-ecr-access --ssh-access
更新标签
中eksctl没有用于更新节点组标签的特定命令,但可以通过以下方式轻松kubectl实现:
kubectl label nodes -l alpha.eksctl.io/nodegroup-name=ng-1 new-label=foo
SSH 访问
您可以通过publicKeyPath在节点组配置中配置一个publicKeyName和publicKey,为节点组启用 SSH 访问。或者,您可以使用 AWS 系统管理器 (SSM) 通过 SSH 连接到节点,方法是将节点组配置为:enableSsm
managedNodeGroups: - name: ng-1 instanceType: m5.large desiredCapacity: 1 ssh: # import public key from file publicKeyPath: ~/.ssh/id_rsa_tests.pub - name: ng-2 instanceType: m5.large desiredCapacity: 1 ssh: # use existing EC2 key publicKeyName: ec2_dev_key - name: ng-3 instanceType: m5.large desiredCapacity: 1 ssh: # import inline public key publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqZEdzvHnK/GVP8nLngRHu/GDi/3PeES7+Bx6l3koXn/Oi/UmM9/jcW5XGziZ/oe1cPJ777eZV7muEvXg5ZMQBrYxUtYCdvd8Rt6DIoSqDLsIPqbuuNlQoBHq/PU2IjpWnp/wrJQXMk94IIrGjY8QHfCnpuMENCucVaifgAhwyeyuO5KiqUmD8E0RmcsotHKBV9X8H5eqLXd8zMQaPl+Ub7j5PG+9KftQu0F/QhdFvpSLsHaxvBzA5nhIltjkaFcwGQnD1rpCM3+UnQE7Izoa5Yt1xoUWRwnF+L2TKovW7+bYQ1kxsuuiX149jXTCJDVjkYCqi7HkrXYqcC1sbsror someuser@hostname" - name: ng-4 instanceType: m5.large desiredCapacity: 1 ssh: # enable SSH using SSM enableSsm: true