

的版本 5 (V5) AWS Tools for PowerShell 已经发布！

有关重大更改和迁移应用程序的信息，请参阅[迁移主题](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

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

# 使用适用于 PowerShell V5 的工具的 Amazon EKS 示例
<a name="powershell_eks_code_examples"></a>

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

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

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

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `Add-EKSResourceTag`
<a name="eks_TagResource_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 将指定的标签与具有指定 resourceArn 的资源相关联。**  

```
Add-EKSResourceTag -ResourceArn "arn:aws:eks:us-west-2:012345678912:cluster/PROD" -Tag @{Name = "EKSPRODCLUSTER"}
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [TagResource](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSCluster`
<a name="eks_DescribeCluster_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeCluster](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSClusterList`
<a name="eks_ListClusters_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 列出了您在 AWS 账户 指定区域内的 Amazon EKS 集群。**  

```
Get-EKSClusterList
```
**输出**：  

```
 PROD
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListClusters](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSFargateProfile`
<a name="eks_DescribeFargateProfile_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 返回有关 Far AWS 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeFargateProfile](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSFargateProfileList`
<a name="eks_ListFargateProfiles_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 列出了与指定区域中指定集群关联的 AWS Fargate 配置文件。 AWS 账户 **  

```
Get-EKSFargateProfileList -ClusterName "TEST"
```
**输出**：  

```
EKSFargate
EKSFargateProfile
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListFargateProfiles](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSNodegroup`
<a name="eks_DescribeNodegroup_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeNodegroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSNodegroupList`
<a name="eks_ListNodegroups_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 列出了与您在 AWS 账户 指定区域中的指定集群关联的 Amazon EKS 节点组。**  

```
Get-EKSNodegroupList -ClusterName PROD
```
**输出**：  

```
 ProdEKSNodeGroup
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListNodegroups](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSResourceTag`
<a name="eks_ListTagsForResource_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 列出 Amazon EKS 资源的标签。**  

```
Get-EKSResourceTag -ResourceArn "arn:aws:eks:us-west-2:012345678912:cluster/PROD"
```
**输出**：  

```
Key  Value
---  -----
Name EKSPRODCLUSTER
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListTagsForResource](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSUpdate`
<a name="eks_DescribeUpdate_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeUpdate](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-EKSUpdateList`
<a name="eks_ListUpdates_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 列出了在指定区域中与您 AWS 账户的 Amazon EKS 集群或托管节点组相关的更新。**  

```
Get-EKSUpdateList -Name "PROD"
```
**输出**：  

```
ee708232-7d2e-4ed7-9270-d0b5176f0726
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ListUpdates](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EKSCluster`
<a name="eks_CreateCluster_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 参考 (V* 5) [CreateCluster](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EKSFargateProfile`
<a name="eks_CreateFargateProfile_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 为您的 Amazon EKS 集群创建 AWS 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateFargateProfile](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-EKSNodeGroup`
<a name="eks_CreateNodegroup_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateNodegroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EKSCluster`
<a name="eks_DeleteCluster_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteCluster](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EKSFargateProfile`
<a name="eks_DeleteFargateProfile_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 1：此 cmdlet 删除了 Fargate 配置文件 AWS 。删除 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteFargateProfile](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EKSNodegroup`
<a name="eks_DeleteNodegroup_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DeleteNodegroup](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Remove-EKSResourceTag`
<a name="eks_UntagResource_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UntagResource](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Update-EKSClusterConfig`
<a name="eks_UpdateClusterConfig_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UpdateClusterConfig](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Update-EKSClusterVersion`
<a name="eks_UpdateClusterVersion_powershell_topic"></a>

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

**适用于 PowerShell V5 的工具**  
**示例 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 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [UpdateClusterVersion](https://docs.aws.amazon.com/powershell/v5/reference)中的。