View a markdown version of this page

使用 部署 OTel Container Insights CloudFormation - Amazon CloudWatch

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 部署 OTel Container Insights CloudFormation

您可以使用 CloudFormation 範本,將 OTel Container Insights 部署為基礎設施做為程式碼。此方法最適合透過 IaC 管道管理叢集,並希望進行可重複、版本控制的部署的團隊。

範本會在啟用 amazon-cloudwatch-observability OTel Container Insights 的情況下安裝 EKS 附加元件。如果您偏好 Kubernetes 原生套件管理,請參閱 使用 Helm 部署 OTel 容器洞見

先決條件

使用 部署 OTel Container Insights 之前 CloudFormation,請確認您符合下列要求。

  • 執行 Kubernetes 1.28 版或更新版本的現有 Amazon EKS 叢集

  • AWS CLI 2.15.0 版或更新版本

  • kubectl 設定為與您的目標叢集通訊

  • 建立 CloudFormation 堆疊的 IAM 許可

  • 從叢集到 CloudWatch 端點的傳出網際網路存取

使用 部署 CloudFormation

使用 CloudFormation 範本在單一堆疊中部署 CloudWatch 可觀測性附加元件、所需的 IAM 角色和 Pod Identity 關聯。此範本使用 AWS::EKS::Addon 資源來安裝已啟用 OTel Container Insights 的附加元件。

CloudFormation 範本

下列範本會建立您在 Amazon EKS 叢集上啟用 OTel Container Insights 所需的完整資源集。

AWSTemplateFormatVersion: '2010-09-09' Description: Deploy OTel Container Insights on an EKS cluster Parameters: ClusterName: Type: String Description: The name of your EKS cluster Resources: CloudWatchAgentRole: Type: AWS::IAM::Role Properties: RoleName: EKS-CloudWatch-Observability-Role AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: pods.eks.amazonaws.com Action: - sts:AssumeRole - sts:TagSession ManagedPolicyArns: - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy PodIdentityAssociation: Type: AWS::EKS::PodIdentityAssociation Properties: ClusterName: !Ref ClusterName Namespace: amazon-cloudwatch ServiceAccount: cloudwatch-agent RoleArn: !GetAtt CloudWatchAgentRole.Arn CloudWatchObservabilityAddon: Type: AWS::EKS::Addon DependsOn: PodIdentityAssociation Properties: ClusterName: !Ref ClusterName AddonName: amazon-cloudwatch-observability AddonVersion: v6.2.0-eksbuild.1 ConfigurationValues: '{"otelContainerInsights":{"enabled":true}}' ServiceAccountRoleArn: !GetAtt CloudWatchAgentRole.Arn ResolveConflicts: OVERWRITE

此範本會建立以下資源:

  • 連接 CloudWatchAgentServerPolicy受管政策的 IAM 角色

  • 將角色映射至 CloudWatch 代理程式服務帳戶的 EKS Pod Identity 關聯

  • 已啟用 amazon-cloudwatch-observability OTel Container Insights 的 EKS 附加元件

部署 CloudFormation 堆疊

使用 從範本 AWS CLI 建立 CloudFormation 堆疊。

部署堆疊
  1. 將上述範本儲存至名為 的檔案otel-container-insights.yaml

  2. 執行下列命令。使用 Amazon EKS 叢集的名稱取代 cluster-name

    aws cloudformation create-stack \ --stack-name otel-container-insights \ --template-body file://otel-container-insights.yaml \ --parameters ParameterKey=ClusterName,ParameterValue=cluster-name \ --capabilities CAPABILITY_NAMED_IAM
  3. 等待堆疊建立完成。

    aws cloudformation wait stack-create-complete \ --stack-name otel-container-insights
  4. 確認堆疊狀態為 CREATE_COMPLETE

    aws cloudformation describe-stacks \ --stack-name otel-container-insights \ --query "Stacks[0].StackStatus" \ --output text

驗證部署

CloudFormation 堆疊建立完成後,請確認附加元件正在執行並將資料傳送至 CloudWatch。

驗證部署
  1. 確認 CloudWatch 代理程式 Pod 正在執行。

    kubectl get pods -n amazon-cloudwatch -l app.kubernetes.io/name=cloudwatch-agent

    所有 Pod 必須顯示Running狀態。

  2. 透過 https://console.aws.amazon.com/cloudwatch/ 開啟 CloudWatch 主控台。

  3. 在導覽窗格中,選擇容器洞見

  4. 確認您的叢集出現在叢集清單中,且指標正在填入。

指標通常會在部署完成後 3 到 5 分鐘內出現在 CloudWatch 中。

移除部署

若要移除 CloudFormation 範本建立的所有資源,請刪除堆疊。

aws cloudformation delete-stack \ --stack-name otel-container-insights