AWS EKS使用Cloudwatch Container Insights

15 篇文章 1 订阅
14 篇文章 0 订阅

安装Container Insights作为DaemonSet

为工作节点附加Cloudwatch权限,$ROLE_NAME为集群节点的IAM角色

aws iam attach-role-policy \
  --role-name $ROLE_NAME \
  --policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy

部署Container Insights,test-eks为集群名称,${AWS_REGION}填写EKS集群所在区域

curl -s https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluentd-quickstart.yaml | sed "s/{{cluster_name}}/test-eks/;s/{{region_name}}/${AWS_REGION}/" | kubectl apply -f -
## output
namespace/amazon-cloudwatch created
serviceaccount/cloudwatch-agent created
clusterrole.rbac.authorization.k8s.io/cloudwatch-agent-role created
clusterrolebinding.rbac.authorization.k8s.io/cloudwatch-agent-role-binding created
configmap/cwagentconfig created
daemonset.apps/cloudwatch-agent created
configmap/cluster-info created
serviceaccount/fluentd created
clusterrole.rbac.authorization.k8s.io/fluentd-role created
clusterrolebinding.rbac.authorization.k8s.io/fluentd-role-binding created

查看

kubectl -n amazon-cloudwatch get daemonsets
## output
NAME                 DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
cloudwatch-agent     2         2         2       2            2           <none>          26s
fluentd-cloudwatch   2         2         2       2            2           <none>          23s

Cloudwatch查看指标

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AWS SAM(Serverless Application Model)提供了一个方便的方式来生成和管理 Lambda 函数和其他服务资源。如果您想将 CloudWatch 日志发送到 Lambda 函数进行处理,可以通过以下步骤实现: 1. 在 `template.yaml` 文件中为 Lambda 函数定义一个 CloudWatch 日志组,例如: ``` Resources: MyFunction: Type: AWS::Serverless::Function Properties: ... Environment: Variables: ... Policies: - AWSLambdaBasicExecutionRole Events: MyEvent: Type: Schedule Properties: Schedule: rate(1 minute) MyFunctionLogGroup: Type: AWS::Logs::LogGroup Properties: LogGroupName: "/aws/lambda/MyFunction" RetentionInDays: 7 ``` 这将在 CloudWatch 中创建一个日志组 `/aws/lambda/MyFunction`,并将其与 Lambda 函数 `MyFunction` 关联。 2. 在 Lambda 函数中添加 CloudWatch 日志处理程序。在 Python 中,您可以使用 `boto3` 库和 `json` 模块来解析和处理日志事件,例如: ```python import boto3 import json def lambda_handler(event, context): logs = boto3.client('logs') for log_event in event['awslogs']['data']: payload = json.loads(log_event['message']) # Process the log message here ``` 3. 在 `template.yaml` 文件中将 Lambda 函数与 CloudWatch 日志组关联,例如: ``` Resources: MyFunction: Type: AWS::Serverless::Function Properties: ... Environment: Variables: ... Policies: - AWSLambdaBasicExecutionRole Events: MyEvent: Type: Schedule Properties: Schedule: rate(1 minute) MyFunctionLogGroup: Type: AWS::Logs::LogGroup Properties: LogGroupName: "/aws/lambda/MyFunction" RetentionInDays: 7 MyFunctionLogSubscriptionFilter: Type: AWS::Logs::SubscriptionFilter Properties: DestinationArn: !GetAtt MyFunction.Arn FilterPattern: "" LogGroupName: !Ref MyFunctionLogGroup ``` 这将在 CloudWatch 日志组 `/aws/lambda/MyFunction` 中添加一个订阅过滤器,将所有日志事件转发到 `MyFunction` Lambda 函数进行处理。 注意:这只是一个简单的示例,实际的实现可能会因环境和需求而异。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值