

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 [AWS](https://github.com/awsdocs/aws-doc-sdk-examples)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Tools for PowerShell V5 を使用した Amazon EKS の例
<a name="powershell_5_eks_code_examples"></a>

次のコード例は、Amazon EKS で AWS Tools for PowerShell V5 を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

*アクション*はより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

**Topics**
+ [アクション](#actions)

## アクション
<a name="actions"></a>

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

次のコード例は、`Add-EKSResourceTag` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、指定されたタグを、指定された resourceArn を持つリソースに関連付けます。**  

```
Add-EKSResourceTag -ResourceArn "arn:aws:eks:us-west-2:012345678912:cluster/PROD" -Tag @{Name = "EKSPRODCLUSTER"}
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V5)* の「[TagResource](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSCluster` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、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 コマンドレットリファレンス (V5)* の「[DescribeCluster](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSClusterList` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、指定されたリージョン AWS アカウント の にある Amazon EKS クラスターを一覧表示します。**  

```
Get-EKSClusterList
```
**出力:**  

```
 PROD
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V5)* の「[ListClusters](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSFargateProfile` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、 AWS Fargate プロファイルに関する説明情報を返します。**  

```
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 コマンドレットリファレンス (V5)* の「[DescribeFargateProfile](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSFargateProfileList` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、指定されたリージョンの 内の指定されたクラスターに関連付けられた AWS Fargate プロファイル AWS アカウント を一覧表示します。**  

```
Get-EKSFargateProfileList -ClusterName "TEST"
```
**出力:**  

```
EKSFargate
EKSFargateProfile
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V5)* の「[ListFargateProfiles](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSNodegroup` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、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 コマンドレットリファレンス (V5)* の「[DescribeNodegroup](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSNodegroupList` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、指定されたリージョンの 内の指定されたクラスターに関連付けられた Amazon EKS ノードグループ AWS アカウント を一覧表示します。 **  

```
Get-EKSNodegroupList -ClusterName PROD
```
**出力:**  

```
 ProdEKSNodeGroup
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V5)* の「[ListNodegroups](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSResourceTag` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、Amazon EKS リソースのタグを一覧表示します。 **  

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

```
Key  Value
---  -----
Name EKSPRODCLUSTER
```
+  API の詳細については、AWS Tools for PowerShell コマンドレットリファレンス (V5) の「[ListTagsForResource](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Get-EKSUpdate` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、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 コマンドレットリファレンス (V5)* の「[DescribeUpdate](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Get-EKSUpdateList` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、指定されたリージョンの 内の Amazon EKS クラスターまたはマネージドノードグループに関連付けられた更新 AWS アカウントを一覧表示します。**  

```
Get-EKSUpdateList -Name "PROD"
```
**出力:**  

```
ee708232-7d2e-4ed7-9270-d0b5176f0726
```
+  API の詳細については、*AWS Tools for PowerShell コマンドレットリファレンス (V5)* の「[ListUpdates](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`New-EKSCluster` を使用する方法を示しています。

**Tools for 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 コマンドレットリファレンス (V5)* の「[CreateCluster](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`New-EKSFargateProfile` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、Amazon EKS クラスターの AWS Fargate プロファイルを作成します。Fargate インフラストラクチャでポッドをスケジュールできるようにするには、クラスター内に少なくとも 1 つの Fargate プロファイルが必要です。**  

```
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 コマンドレットリファレンス (V5)* の「[CreateFargateProfile](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`New-EKSNodeGroup` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、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 コマンドレットリファレンス (V5)* の「[CreateNodegroup](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Remove-EKSCluster` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、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 コマンドレットリファレンス (V5)* の「[DeleteCluster](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Remove-EKSFargateProfile` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは AWS Fargate プロファイルを削除します。Fargate プロファイルを削除すると、そのプロファイルで Fargate で作成された Fargate 上で実行中のポッドは削除されます。**  

```
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 コマンドレットリファレンス (V5)* の「[DeleteFargateProfile](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Remove-EKSNodegroup` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、クラスターの 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 コマンドレットリファレンス (V5)* の「[DeleteNodegroup](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Remove-EKSResourceTag` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、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 コマンドレットリファレンス (V5) の「[UntagResource](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。**

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

次のコード例は、`Update-EKSClusterConfig` を使用する方法を示しています。

**Tools for 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 コマンドレットリファレンス (V5)* の「[UpdateClusterConfig](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

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

次のコード例は、`Update-EKSClusterVersion` を使用する方法を示しています。

**Tools for PowerShell V5**  
**例 1: このコマンドレットは、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 コマンドレットリファレンス (V5)* の「[UpdateClusterVersion](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。