View a markdown version of this page

使用适用于 PowerShell V4 的工具的 Amazon EKS 示例 - Amazon Tools for PowerShell (版本 4)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

Amazon Tools for PowerShell V4 的支持已到期。

我们建议您迁移到 Amazon Tools for PowerShell V5 。有关如何迁移的更多详细信息和信息,请参阅我们的终止支持公告

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用适用于 PowerShell V4 的工具的 Amazon EKS 示例

以下代码示例向您展示了如何使用带有 Amazon EKS 的 Amazon Tools for PowerShell V4 来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示了如何使用 Add-EKSResourceTag

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 将指定的标签与具有指定 resourceArn 的资源相关联。

Add-EKSResourceTag -ResourceArn "arn:aws:eks:us-west-2:012345678912:cluster/PROD" -Tag @{Name = "EKSPRODCLUSTER"}
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) TagResource中的。

以下代码示例演示了如何使用 Get-EKSCluster

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 返回有关 Amazon EKS 集群的描述性信息。

Get-EKSCluster -Name "PROD"

输出

Arn : arn:aws:eks:us-west-2:012345678912:cluster/PROD CertificateAuthority : Amazon.EKS.Model.Certificate ClientRequestToken : CreatedAt : 12/25/2019 6:46:17 AM Endpoint : https://669608765450FBBE54D1D78A3D71B72C.gr8.us-west-2.eks.amazonaws.com Identity : Amazon.EKS.Model.Identity Logging : Amazon.EKS.Model.Logging Name : PROD PlatformVersion : eks.7 ResourcesVpcConfig : Amazon.EKS.Model.VpcConfigResponse RoleArn : arn:aws:iam::012345678912:role/eks-iam-role Status : ACTIVE Tags : {} Version : 1.14
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DescribeCluster中的。

以下代码示例演示了如何使用 Get-EKSClusterList

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 列出了您在 Amazon Web Services 账户 指定区域内的 Amazon EKS 集群。

Get-EKSClusterList

输出

PROD
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) ListClusters中的。

以下代码示例演示了如何使用 Get-EKSFargateProfile

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 返回有关 Far Amazon gate 配置文件的描述性信息。

Get-EKSFargateProfile -FargateProfileName "EKSFargate" -ClusterName "TEST"

输出

ClusterName : TEST CreatedAt : 12/26/2019 12:34:47 PM FargateProfileArn : arn:aws:eks:us-east-2:012345678912:fargateprofile/TEST/EKSFargate/42b7a119-e16b-a279-ce97-bdf303adec92 FargateProfileName : EKSFargate PodExecutionRoleArn : arn:aws:iam::012345678912:role/AmazonEKSFargatePodExecutionRole Selectors : {Amazon.EKS.Model.FargateProfileSelector} Status : ACTIVE Subnets : {subnet-0cd976f08d5fbfaae, subnet-02f6ff500ff2067a0} Tags : {}
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DescribeFargateProfile中的。

以下代码示例演示了如何使用 Get-EKSFargateProfileList

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 列出了与指定区域中指定集群关联的 Amazon Fargate 配置文件。 Amazon Web Services 账户

Get-EKSFargateProfileList -ClusterName "TEST"

输出

EKSFargate EKSFargateProfile
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) ListFargateProfiles中的。

以下代码示例演示了如何使用 Get-EKSNodegroup

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 返回有关 Amazon EKS 节点组的描述性信息。

Get-EKSNodegroup -NodegroupName "ProdEKSNodeGroup" -ClusterName "PROD"

输出

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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DescribeNodegroup中的。

以下代码示例演示了如何使用 Get-EKSNodegroupList

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 列出了与您在 Amazon Web Services 账户 指定区域中的指定集群关联的 Amazon EKS 节点组。

Get-EKSNodegroupList -ClusterName PROD

输出

ProdEKSNodeGroup
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) ListNodegroups中的。

以下代码示例演示了如何使用 Get-EKSResourceTag

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 列出 Amazon EKS 资源的标签。

Get-EKSResourceTag -ResourceArn "arn:aws:eks:us-west-2:012345678912:cluster/PROD"

输出

Key Value --- ----- Name EKSPRODCLUSTER
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) ListTagsForResource中的。

以下代码示例演示了如何使用 Get-EKSUpdate

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 返回有关针对 Amazon EKS 集群或关联的托管式节点组进行的更新的描述性信息。

Get-EKSUpdate -Name "PROD" -UpdateId "ee708232-7d2e-4ed7-9270-d0b5176f0726"

输出

CreatedAt : 12/25/2019 5:03:07 PM Errors : {} Id : ee708232-7d2e-4ed7-9270-d0b5176f0726 Params : {Amazon.EKS.Model.UpdateParam} Status : Successful Type : LoggingUpdate
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DescribeUpdate中的。

以下代码示例演示了如何使用 Get-EKSUpdateList

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 列出了在指定区域中与您 Amazon Web Services 账户的 Amazon EKS 集群或托管节点组相关的更新。

Get-EKSUpdateList -Name "PROD"

输出

ee708232-7d2e-4ed7-9270-d0b5176f0726
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) ListUpdates中的。

以下代码示例演示了如何使用 New-EKSCluster

适用于 PowerShell V4 的工具

示例 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) CreateCluster中的。

以下代码示例演示了如何使用 New-EKSFargateProfile

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 为您的 Amazon EKS 集群创建 Amazon Fargate 配置文件。您必须在集群中至少有一个 Fargate 配置文件,才能在 Fargate 基础设施上安排容器组(pod)。

New-EKSFargateProfile -FargateProfileName EKSFargateProfile -ClusterName TEST -Subnet "subnet-02f6ff500ff2067a0", "subnet-0cd976f08d5fbfaae" -PodExecutionRoleArn arn:aws:iam::012345678912:role/AmazonEKSFargatePodExecutionRole -Selector @{Namespace="default"}

输出

ClusterName : TEST CreatedAt : 12/26/2019 12:38:21 PM FargateProfileArn : arn:aws:eks:us-east-2:012345678912:fargateprofile/TEST/EKSFargateProfile/20b7a11b-8292-41c1-bc56-ffa5e60f6224 FargateProfileName : EKSFargateProfile PodExecutionRoleArn : arn:aws:iam::012345678912:role/AmazonEKSFargatePodExecutionRole Selectors : {Amazon.EKS.Model.FargateProfileSelector} Status : CREATING Subnets : {subnet-0cd976f08d5fbfaae, subnet-02f6ff500ff2067a0} Tags : {}
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) CreateFargateProfile中的。

以下代码示例演示了如何使用 New-EKSNodeGroup

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 为 Amazon EKS 集群创建托管式 Worker 节点组。您只能为集群创建等于集群的当前 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 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) CreateNodegroup中的。

以下代码示例演示了如何使用 Remove-EKSCluster

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 删除 Amazon EKS 集群控制面板。

Remove-EKSCluster -Name "DEV-KUBE-CL"

输出

Confirm Are you sure you want to perform this action? Performing the operation "Remove-EKSCluster (DeleteCluster)" on target "DEV-KUBE-CL". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y Arn : arn:aws:eks:us-west-2:012345678912:cluster/DEV-KUBE-CL CertificateAuthority : Amazon.EKS.Model.Certificate ClientRequestToken : CreatedAt : 12/25/2019 9:33:25 AM Endpoint : https://02E6D31E3E4F8C15D7BE7F58D527776A.yl4.us-west-2.eks.amazonaws.com Identity : Amazon.EKS.Model.Identity Logging : Amazon.EKS.Model.Logging Name : DEV-KUBE-CL PlatformVersion : eks.7 ResourcesVpcConfig : Amazon.EKS.Model.VpcConfigResponse RoleArn : arn:aws:iam::012345678912:role/eks-iam-role Status : DELETING Tags : {} Version : 1.14
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DeleteCluster中的。

以下代码示例演示了如何使用 Remove-EKSFargateProfile

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 删除了 Fargate 配置文件 Amazon 。删除 Fargate 配置文件时,将删除使用该配置文件创建的在 Fargate 上运行的任何容器组(pod)。

Remove-EKSFargateProfile -FargateProfileName "EKSFargate" -ClusterName "TEST"

输出

Confirm Are you sure you want to perform this action? Performing the operation "Remove-EKSFargateProfile (DeleteFargateProfile)" on target "EKSFargate". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y ClusterName : TEST CreatedAt : 12/26/2019 12:34:47 PM FargateProfileArn : arn:aws:eks:us-east-2:012345678912:fargateprofile/TEST/EKSFargate/42b7a119-e16b-a279-ce97-bdf303adec92 FargateProfileName : EKSFargate PodExecutionRoleArn : arn:aws:iam::012345678912:role/AmazonEKSFargatePodExecutionRole Selectors : {Amazon.EKS.Model.FargateProfileSelector} Status : DELETING Subnets : {subnet-0cd976f08d5fbfaae, subnet-02f6ff500ff2067a0} Tags : {}
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DeleteFargateProfile中的。

以下代码示例演示了如何使用 Remove-EKSNodegroup

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 删除集群的 Amazon EKS 节点组。

Remove-EKSNodegroup -NodegroupName "ProdEKSNodeGroup" -ClusterName "PROD"

输出

Confirm Are you sure you want to perform this action? Performing the operation "Remove-EKSNodegroup (DeleteNodegroup)" on target "ProdEKSNodeGroup". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y 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 11:01:16 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 : Amazon.EKS.Model.NodegroupResources ScalingConfig : Amazon.EKS.Model.NodegroupScalingConfig Status : DELETING Subnets : {subnet-0d1a9fff35efa7691, subnet-0a3f4928edbc224d4} Tags : {} Version : 1.14
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) DeleteNodegroup中的。

以下代码示例演示了如何使用 Remove-EKSResourceTag

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 从 EKS 资源中删除指定的标签。

Remove-EKSResourceTag -ResourceArn "arn:aws:eks:us-west-2:012345678912:cluster/PROD" -TagKey "Name"

输出

Confirm Are you sure you want to perform this action? Performing the operation "Remove-EKSResourceTag (UntagResource)" on target "arn:aws:eks:us-west-2:012345678912:cluster/PROD". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) UntagResource中的。

以下代码示例演示了如何使用 Update-EKSClusterConfig

适用于 PowerShell V4 的工具

示例 1:更新 Amazon EKS 集群配置。在更新期间,集群将继续运行。

Update-EKSClusterConfig -Name "PROD" -Logging_ClusterLogging @{Types="api","audit","authenticator","controllerManager","scheduler",Enabled="True"}

输出

CreatedAt : 12/25/2019 5:03:07 PM Errors : {} Id : ee708232-7d2e-4ed7-9270-d0b5176f0726 Params : {Amazon.EKS.Model.UpdateParam} Status : InProgress Type : LoggingUpdate
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) UpdateClusterConfig中的。

以下代码示例演示了如何使用 Update-EKSClusterVersion

适用于 PowerShell V4 的工具

示例 1:此 cmdlet 将 Amazon EKS 集群更新到指定的 Kubernetes 版本。在更新期间,集群将继续运行。

Update-EKSClusterVersion -Name "PROD-KUBE-CL" -Version 1.14

输出

CreatedAt : 12/26/2019 9:50:37 AM Errors : {} Id : ef186eff-3b3a-4c25-bcfc-3dcdf9e898a8 Params : {Amazon.EKS.Model.UpdateParam, Amazon.EKS.Model.UpdateParam} Status : InProgress Type : VersionUpdate
  • 有关 API 的详细信息,请参阅 Amazon Tools for PowerShell Cmdlet 参考 (V 4) UpdateClusterVersion中的。