CreateNodegroup 搭配 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

CreateNodegroup 搭配 CLI 使用

下列程式碼範例示範如何使用 CreateNodegroup

CLI
AWS CLI

範例 1:為 Amazon EKS 叢集建立受管節點群組

下列create-nodegroup範例會為 Amazon EKS 叢集建立受管節點群組。

aws eks create-nodegroup \ --cluster-name my-eks-cluster \ --nodegroup-name my-eks-nodegroup \ --node-role arn:aws:iam::111122223333:role/role-name \ --subnets "subnet-0e2907431c9988b72" "subnet-04ad87f71c6e5ab4d" "subnet-09d912bb63ef21b9a" \ --scaling-config minSize=1,maxSize=3,desiredSize=1 \ --region us-east-2

輸出:

{ "nodegroup": { "nodegroupName": "my-eks-nodegroup", "nodegroupArn": "arn:aws:eks:us-east-2:111122223333:nodegroup/my-eks-cluster/my-eks-nodegroup/bac7550f-b8b8-5fbb-4f3e-7502a931119e", "clusterName": "my-eks-cluster", "version": "1.26", "releaseVersion": "1.26.12-20240329", "createdAt": "2024-04-04T13:19:32.260000-04:00", "modifiedAt": "2024-04-04T13:19:32.260000-04:00", "status": "CREATING", "capacityType": "ON_DEMAND", "scalingConfig": { "minSize": 1, "maxSize": 3, "desiredSize": 1 }, "instanceTypes": [ "t3.medium" ], "subnets": [ "subnet-0e2907431c9988b72, subnet-04ad87f71c6e5ab4d, subnet-09d912bb63ef21b9a" ], "amiType": "AL2_x86_64", "nodeRole": "arn:aws:iam::111122223333:role/role-name", "diskSize": 20, "health": { "issues": [] }, "updateConfig": { "maxUnavailable": 1 }, "tags": {} } }

如需詳細資訊,請參閱 Amazon EKS 使用者指南中的建立受管節點群組

範例 2:為具有自訂執行個體類型和磁碟大小的 Amazon EKS 叢集建立受管節點群組

下列create-nodegroup範例會為具有自訂執行個體類型和磁碟大小的 Amazon EKS 叢集建立受管節點群組。

aws eks create-nodegroup \ --cluster-name my-eks-cluster \ --nodegroup-name my-eks-nodegroup \ --node-role arn:aws:iam::111122223333:role/role-name \ --subnets "subnet-0e2907431c9988b72" "subnet-04ad87f71c6e5ab4d" "subnet-09d912bb63ef21b9a" \ --scaling-config minSize=1,maxSize=3,desiredSize=1 \ --capacity-type ON_DEMAND \ --instance-types 'm5.large' \ --disk-size 50 \ --region us-east-2

輸出:

{ "nodegroup": { "nodegroupName": "my-eks-nodegroup", "nodegroupArn": "arn:aws:eks:us-east-2:111122223333:nodegroup/my-eks-cluster/my-eks-nodegroup/c0c7551b-e4f9-73d9-992c-a450fdb82322", "clusterName": "my-eks-cluster", "version": "1.26", "releaseVersion": "1.26.12-20240329", "createdAt": "2024-04-04T13:46:07.595000-04:00", "modifiedAt": "2024-04-04T13:46:07.595000-04:00", "status": "CREATING", "capacityType": "ON_DEMAND", "scalingConfig": { "minSize": 1, "maxSize": 3, "desiredSize": 1 }, "instanceTypes": [ "m5.large" ], "subnets": [ "subnet-0e2907431c9988b72", "subnet-04ad87f71c6e5ab4d", "subnet-09d912bb63ef21b9a" ], "amiType": "AL2_x86_64", "nodeRole": "arn:aws:iam::111122223333:role/role-name", "diskSize": 50, "health": { "issues": [] }, "updateConfig": { "maxUnavailable": 1 }, "tags": {} } }

如需詳細資訊,請參閱 Amazon EKS 使用者指南中的建立受管節點群組

範例 3:為具有自訂執行個體類型、磁碟大小、ami 類型、容量類型、Update-config、標籤、污點和標籤的 Amazon EKS 叢集建立受管節點群組。

下列create-nodegroup範例會為具有自訂執行個體類型、磁碟大小、ami 類型、容量類型、更新組態、標籤、污點和標籤的 Amazon EKS 叢集建立受管節點群組。

aws eks create-nodegroup \ --cluster-name my-eks-cluster \ --nodegroup-name my-eks-nodegroup \ --node-role arn:aws:iam::111122223333:role/role-name \ --subnets "subnet-0e2907431c9988b72" "subnet-04ad87f71c6e5ab4d" "subnet-09d912bb63ef21b9a" \ --scaling-config minSize=1,maxSize=5,desiredSize=4 \ --instance-types 't3.large' \ --disk-size 50 \ --ami-type AL2_x86_64 \ --capacity-type SPOT \ --update-config maxUnavailable=2 \ --labels '{"my-eks-nodegroup-label-1": "value-1" , "my-eks-nodegroup-label-2": "value-2"}' \ --taints '{"key": "taint-key-1" , "value": "taint-value-1", "effect": "NO_EXECUTE"}' \ --tags '{"my-eks-nodegroup-key-1": "value-1" , "my-eks-nodegroup-key-2": "value-2"}'

輸出:

{ "nodegroup": { "nodegroupName": "my-eks-nodegroup", "nodegroupArn": "arn:aws:eks:us-east-2:111122223333:nodegroup/my-eks-cluster/my-eks-nodegroup/88c75524-97af-0cb9-a9c5-7c0423ab5314", "clusterName": "my-eks-cluster", "version": "1.26", "releaseVersion": "1.26.12-20240329", "createdAt": "2024-04-04T14:05:07.940000-04:00", "modifiedAt": "2024-04-04T14:05:07.940000-04:00", "status": "CREATING", "capacityType": "SPOT", "scalingConfig": { "minSize": 1, "maxSize": 5, "desiredSize": 4 }, "instanceTypes": [ "t3.large" ], "subnets": [ "subnet-0e2907431c9988b72", "subnet-04ad87f71c6e5ab4d", "subnet-09d912bb63ef21b9a" ], "amiType": "AL2_x86_64", "nodeRole": "arn:aws:iam::111122223333:role/role-name", "labels": { "my-eks-nodegroup-label-2": "value-2", "my-eks-nodegroup-label-1": "value-1" }, "taints": [ { "key": "taint-key-1", "value": "taint-value-1", "effect": "NO_EXECUTE" } ], "diskSize": 50, "health": { "issues": [] }, "updateConfig": { "maxUnavailable": 2 }, "tags": { "my-eks-nodegroup-key-1": "value-1", "my-eks-nodegroup-key-2": "value-2" } } }

如需詳細資訊,請參閱 Amazon EKS 使用者指南中的建立受管節點群組

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateNodegroup

PowerShell
for PowerShell 工具

範例 1:此 cmdlet 會為 Amazon EKS 叢集建立受管工作者節點群組。您只能為叢集建立一個等於叢集目前 Kubernetes 版本的節點群組。所有節點群組都是使用叢集之個別次要 Kubernetes 版本的最新 AMI 版本來建立。

New-EKSNodeGroup -NodeGroupName "ProdEKSNodeGroup" -AmiType "AL2_x86_64" -DiskSize 40 -ClusterName "PROD" -ScalingConfig_DesiredSize 2 -ScalingConfig_MinSize 2 -ScalingConfig_MaxSize 5 -InstanceType t3.large -NodeRole "arn:aws:iam::012345678912:role/NodeInstanceRole" -Subnet "subnet-0d1a9fff35efa7691","subnet-0a3f4928edbc224d4"

輸出:

AmiType : AL2_x86_64 ClusterName : PROD CreatedAt : 12/25/2019 10:16:45 AM DiskSize : 40 Health : Amazon.EKS.Model.NodegroupHealth InstanceTypes : {t3.large} Labels : {} ModifiedAt : 12/25/2019 10:16:45 AM NodegroupArn : arn:aws:eks:us-west-2:012345678912:nodegroup/PROD/ProdEKSNodeGroup/7eb79e47-82b6-04d9-e984-95110db6fa85 NodegroupName : ProdEKSNodeGroup NodeRole : arn:aws:iam::012345678912:role/NodeInstanceRole ReleaseVersion : 1.14.7-20190927 RemoteAccess : Resources : ScalingConfig : Amazon.EKS.Model.NodegroupScalingConfig Status : CREATING Subnets : {subnet-0d1a9fff35efa7691, subnet-0a3f4928edbc224d4} Tags : {} Version : 1.14
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 CreateNodegroup