New user sign up using AWS Builder ID
New user sign up using AWS Builder ID is currently unavailable on re:Post. To sign up, please use the AWS Management Console instead.
如果故障排除将 Fluent Bit 与适用于 Amazon EKS 的 Container Insights 集成时遇到的设置问题?
我想故障排除将 Fluent Bit 与适用于 Amazon Elastic Kubernetes Service(Amazon EKS)的 Amazon CloudWatch Container Insights 集成时遇到的设置问题。
简短描述
**注意:**最佳实践是使用 Fluent Bit 代替 Fluentd。有关更多信息,请参阅将日志发送到 CloudWatch Logs。
要允许 Fluent Bit 向 CloudWatch Logs 传输容器日志,您必须向 Fluent Bit 授予 AWS Identity and Access Management(IAM)权限。有关更多信息,请参阅验证先决条件。
要将 Container Insights 与 Fluent Bit 一起使用,请为服务账户(IRSA)设置 IAM 角色,然后在您的 EKS 集群中部署 Container Insights。
解决方法
使用 Fluent Bit 设置 Container Insights
使用 CloudWatchAgentServerPolicy AWS 托管式策略创建一个 cloudwatch-agent 和 fluent-bit 服务账户。
完成以下步骤:
-
运行以下命令来设置环境变量:
export CLUSTER=clustername export AWS_REGION=awsregion
**注意:**将 clustername 和 awsregion 替换为您自己的集群名称和 AWS 区域。
-
运行以下 eksctl 命令使用 IRSA 创建一个 CloudWatch-agent 服务账户:
eksctl create iamserviceaccount \ --name cloudwatch-agent \ --namespace amazon-cloudwatch \ --cluster $CLUSTER \ --attach-policy-arn "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy" \ --approve \ --override-existing-serviceaccounts
-
运行以下 eksctl 命令使用 IRSA 创建 Fluent Bit 服务账户:
eksctl create iamserviceaccount \ --name fluent-bit \ --namespace amazon-cloudwatch \ --cluster $CLUSTER \ --attach-policy-arn "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy" \ --approve \ --override-existing-serviceaccounts
-
要使用快速部署 Container Insights,请运行以下命令
:ClusterName=<my-cluster-name> RegionName=<my-cluster-region> FluentBitHttpPort='2020' FluentBitReadFromHead='Off' [[ ${FluentBitReadFromHead} = 'On' ]] && FluentBitReadFromTail='Off'|| FluentBitReadFromTail='On' [[ -z ${FluentBitHttpPort} ]] && FluentBitHttpServer='Off' || FluentBitHttpServer='On' curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluent-bit-quickstart-enhanced.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/;s/{{region_name}}/'${RegionName}'/;s/{{http_server_toggle}}/"'${FluentBitHttpServer}'"/;s/{{http_server_port}}/"'${FluentBitHttpPort}'"/;s/{{read_from_head}}/"'${FluentBitReadFromHead}'"/;s/{{read_from_tail}}/"'${FluentBitReadFromTail}'"/' | kubectl apply -f -
**注意:**将 my-cluster-name 和 my-cluster-region 替换为您自己的集群名称和区域。前面的命令为 CloudWatch 代理和 Fluent Bit 创建了 ClusterRole、ClusterRoleBinding、ConfigMap 和 DaemonSet。
-
运行以下命令以验证 CloudWatch 代理和 Fluent Bit 是否已部署:
kubectl get pods -n amazon-cloudwatch
部署完成后,CloudWatch 代理会创建日志组 /aws/containerinsights/Cluster_Name/performance。
Fluent Bit 会创建日志组**/aws/containerinsights/Cluster_Name/application, /aws/containerinsights/Cluster_Name/host** 和 /aws/containerinsights/Cluster_Name/dataplane。
故障排除 Fluent Bit 设置问题
Fluent Bit 容器组(pod)崩溃
要检查 Fluent Bit 容器组(pod)日志中是否有错误消息,请完成以下步骤:
-
运行以下命令从 Fluent Bit 容器组(pod)中查找事件:
kubectl -n amazon-cloudwatch logs -l k8s-app=fluent-bit kubectl -n amazon-cloudwatch describe pod fluent_pod pod_name
-
确认 cluster-info 准确无误且没有语法错误。
-
确认所有集群名称和区域值均已设置。有关更多信息,请参阅 GitHub 网站上的 amazon-cloudwatch-container-insights。
Fluent Bit 不向 CloudWatch 发送日志
完成以下步骤排除故障:
-
验证在 Fluent Bit 配置文件中输出插件是否已正确设置。要检查是否存在任何数据传输错误,请运行以下命令查看 Fluent Bit 容器组(pod)日志:
kubectl -n amazon-cloudwatch logs fluent_pod_name
-
确保 Fluent Bit 容器组(pod)具有必要的 IAM 权限,可以创建日志组并将日志流式传输到 CloudWatch。您必须将 CloudWatchAgentServerPolicy IAM 策略附加到在 fluent-bit 服务账户中注释的 IAM 角色。
如果您使用了 IRSA,则必须将 IAM 角色附加到 Worker 节点。有关更多信息,请参阅如何排查 Amazon EKS 中的 IRSA 错误?
如果您没有看到特定的应用程序日志,请确认您的应用程序可以运行。然后,确认应用程序是否可以生成其他类型的日志。如果应用程序运行并生成了日志,则检查 fluent-bit 的容器组(pod)日志,看看是否向 CloudWatch 发送了特定错误。
Fluent Bit 容器组(pod)处于 CreateContainerConfigError 状态
运行以下命令以获取确切的错误消息:
kubectl describe pod pod_name -n amazon-cloudwatch
在命令输出的 Events 部分中,查找错误消息,例如以下消息:
Error syncing pod ("fluent-bit-xxxxxxx"), skipping: failed to "StartContainer" with CreateContainerConfigError: "configmap \"fluent-bit-config\" not found"
如果您看到前面的错误消息,那么说明缺少 Fluent Bit 的 ConfigMap(fluent-bit-config)。重复本文使用 Fluent Bit 设置 Container Insights 部分中的第 4 步。
相关信息
使用 CloudWatch 代理 operator 和 Fluent Bit 快速入门
GitHub 网站上的 Activate debug logging

相关内容
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 9 个月前
- AWS 官方已更新 1 个月前