CreateCluster 搭配 a AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

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

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

CreateCluster 搭配 a AWS SDK 或 CLI 使用

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

CLI
AWS CLI

若要建立新的叢集

此範例命令會在您的預設區域中建立名為 prod 的叢集。

命令:

aws eks create-cluster --name prod \ --role-arn arn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI \ --resources-vpc-config subnetIds=subnet-6782e71e,subnet-e7e761ac,securityGroupIds=sg-6979fe18

輸出:

{ "cluster": { "name": "prod", "arn": "arn:aws:eks:us-west-2:012345678910:cluster/prod", "createdAt": 1527808069.147, "version": "1.10", "roleArn": "arn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI", "resourcesVpcConfig": { "subnetIds": [ "subnet-6782e71e", "subnet-e7e761ac" ], "securityGroupIds": [ "sg-6979fe18" ], "vpcId": "vpc-950809ec" }, "status": "CREATING", "certificateAuthority": {} } }

建立啟用私有端點存取和記錄的新叢集

此範例命令會在預設區域中建立名為 example的叢集,並停用公有端點存取、啟用私有端點存取,以及啟用所有記錄類型。

命令:

aws eks create-cluster --name example --kubernetes-version 1.12 \ --role-arn arn:aws:iam::012345678910:role/example-cluster-ServiceRole-1XWBQWYSFRE2Q \ --resources-vpc-config subnetIds=subnet-0a188dccd2f9a632f,subnet-09290d93da4278664,subnet-0f21dd86e0e91134a,subnet-0173dead68481a583,subnet-051f70a57ed6fcab6,subnet-01322339c5c7de9b4,securityGroupIds=sg-0c5b580845a031c10,endpointPublicAccess=false,endpointPrivateAccess=true \ --logging '{"clusterLogging":[{"types":["api","audit","authenticator","controllerManager","scheduler"],"enabled":true}]}'

輸出:

{ "cluster": { "name": "example", "arn": "arn:aws:eks:us-west-2:012345678910:cluster/example", "createdAt": 1565804921.901, "version": "1.12", "roleArn": "arn:aws:iam::012345678910:role/example-cluster-ServiceRole-1XWBQWYSFRE2Q", "resourcesVpcConfig": { "subnetIds": [ "subnet-0a188dccd2f9a632f", "subnet-09290d93da4278664", "subnet-0f21dd86e0e91134a", "subnet-0173dead68481a583", "subnet-051f70a57ed6fcab6", "subnet-01322339c5c7de9b4" ], "securityGroupIds": [ "sg-0c5b580845a031c10" ], "vpcId": "vpc-0f622c01f68d4afec", "endpointPublicAccess": false, "endpointPrivateAccess": true }, "logging": { "clusterLogging": [ { "types": [ "api", "audit", "authenticator", "controllerManager", "scheduler" ], "enabled": true } ] }, "status": "CREATING", "certificateAuthority": {}, "platformVersion": "eks.3" } }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateCluster

PowerShell
for PowerShell 工具

範例 1:此範例會建立新的叢集,名為 'prod'。

New-EKSCluster -Name prod -ResourcesVpcConfig @{SubnetIds=@("subnet-0a1b2c3d","subnet-3a2b1c0d");SecurityGroupIds="sg-6979fe18"} -RoleArn "arn:aws:iam::012345678901:role/eks-service-role"

輸出:

Arn : arn:aws:eks:us-west-2:012345678901:cluster/prod CertificateAuthority : Amazon.EKS.Model.Certificate ClientRequestToken : CreatedAt : 12/10/2018 9:25:31 PM Endpoint : Name : prod PlatformVersion : eks.3 ResourcesVpcConfig : Amazon.EKS.Model.VpcConfigResponse RoleArn : arn:aws:iam::012345678901:role/eks-service-role Status : CREATING Version : 1.10
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 CreateCluster

Rust
Rust 的 SDK
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

async fn make_cluster( client: &aws_sdk_eks::Client, name: &str, arn: &str, subnet_ids: Vec<String>, ) -> Result<(), aws_sdk_eks::Error> { let cluster = client .create_cluster() .name(name) .role_arn(arn) .resources_vpc_config( VpcConfigRequest::builder() .set_subnet_ids(Some(subnet_ids)) .build(), ) .send() .await?; println!("cluster created: {:?}", cluster); Ok(()) }
  • 如需 API 詳細資訊,請參閱 CreateCluster AWS for Rust SDK 參考中的 API