AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或CreateCluster
一起使用 CLI
以下代码示例演示如何使用 CreateCluster
。
- CLI
-
- AWS CLI
-
创建新集群
此示例命令将在您的默认区域中创建一个名为
prod
的集群。命令:
aws eks create-cluster --name
prod
\ --role-arnarn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI
\ --resources-vpc-configsubnetIds=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-version1.12
\ --role-arnarn:aws:iam::012345678910:role/example-cluster-ServiceRole-1XWBQWYSFRE2Q
\ --resources-vpc-configsubnetIds=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详细信息,请参阅 “CreateCluster AWS CLI
命令参考”。
-
- PowerShell
-
- 用于 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
-
- SDK对于 Rust
-
注意
还有更多相关信息 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
中的 Rust AWS SDK API 参考。
-
操作
CreateFargateProfile