

# Fargate 起動タイプの Amazon EKS クラスターで AWS App Mesh サンプルワークロードを設定する
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-Fargate"></a>

Fargate 起動タイプの Amazon EKS を実行しているクラスターで App Mesh を設定する場合は、以下の手順を使用します。

## IAM 許可を設定する
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh--fargate-iam"></a>

IAM アクセス許可を設定するには、次のコマンドを入力します。{{MyCluster}} をクラスターの名前に置き換えます。

```
eksctl create iamserviceaccount --cluster {{MyCluster}} \
 --namespace howto-k8s-fargate \
 --name appmesh-pod \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshEnvoyAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapDiscoverInstanceAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/CloudWatchLogsFullAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshFullAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapFullAccess \
 --override-existing-serviceaccounts \
 --approve
```

## App Mesh のインストール
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-fargate-install"></a>

App Mesh Kubernetes コントローラーをインストールするには、「[App Mesh コントローラー](https://github.com/aws/eks-charts/tree/master/stable/appmesh-controller#app-mesh-controller)」の手順に従います。Fargate 起動タイプの Amazon EKS の指示に従ってください。

## サンプルアプリケーションをインストールする
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-fargate-application"></a>

「[aws-app-mesh-examples](https://github.com/aws/aws-app-mesh-examples)」には、複数の Kubernetes App Mesh チュートリアルが含まれています。このチュートリアルでは、Fargate 起動タイプの Amazon EKS クラスターで動作するサンプルカラーアプリケーションをインストールします。

**App Mesh サンプルアプリケーションを使用して Container Insights をテストするには**

1. 「[https://github.com/aws/aws-app-mesh-examples/tree/main/walkthroughs/howto-k8s-fargate](https://github.com/aws/aws-app-mesh-examples/tree/main/walkthroughs/howto-k8s-fargate)」の手順に従ってアプリケーションをインストールします。

   これらの手順では、正しい Fargate プロファイルを使用して新しいクラスターを作成することを前提としています。既に設定済みの Amazon EKS クラスターを使用する場合は、次のコマンドを使用して、このデモンストレーション用にそのクラスターを設定できます。{{MyCluster}} をクラスターの名前に置き換えます。

   ```
   eksctl create iamserviceaccount --cluster {{MyCluster}} \
    --namespace howto-k8s-fargate \
    --name appmesh-pod \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshEnvoyAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapDiscoverInstanceAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/CloudWatchLogsFullAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshFullAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapFullAccess \
    --override-existing-serviceaccounts \
    --approve
   ```

   ```
   eksctl create fargateprofile --cluster MyCluster \
   --namespace howto-k8s-fargate --name howto-k8s-fargate
   ```

1. フロントアプリケーションのデプロイをポート転送します。

   ```
   kubectl -n howto-k8s-fargate port-forward deployment/front 8080:8080
   ```

1. フロントアプリをカールする:

   ```
   while true; do  curl -s http://localhost:8080/color; sleep 0.1; echo ; done
   ```

1. CloudWatch コンソールの [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) を開いてください。

1. クラスターが実行されている AWS リージョンで、ナビゲーションペインから [**Metrics**] (メトリクス) を選択します。このメトリクスは、[**ContainerInsights/Prometheus**] 名前空間にあります。

1. CloudWatch Logs イベントを表示するには、ナビゲーションペインで [**Log Groups (ロググループ)**] を選択します。イベントは、ログストリーム ` /aws/containerinsights/{{your_cluster_name}}/prometheus ` のロググループ `kubernetes-pod-appmesh-envoy` にあります 。

## App Mesh テスト環境の削除
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-fargate-delete"></a>

App Mesh とサンプルアプリケーションの使用が終了したら、次のコマンドを使用して不要なリソースを削除します。サンプルアプリケーションを削除するには、次のコマンドを入力します。

```
cd aws-app-mesh-examples/walkthroughs/howto-k8s-fargate/
kubectl delete -f _output/manifest.yaml
```

App Mesh コントローラーを削除するには、次のコマンドを入力します。

```
helm delete appmesh-controller -n appmesh-system
```