將 Fluent Bit 與適用於 Amazon EKS 的容器洞察整合時,如何解決設定問題?
在將 Fluent Bit 與適用於 Amazon Elastic Kubernetes Service (Amazon EKS) 的容器洞察整合時,我想對設定問題進行疑難排解。
簡短描述
Fluent Bit 是輕量級的日誌處理器和轉寄站,可用來收集 Amazon CloudWatch 中的容器日誌。
使用 Fluent Bit 而非 Fluentd (傳統的開放原始碼程式) 是最佳實務,因其資源佔用空間小,且具有 Use_Kubelet 功能。如需詳細資訊,請參閱針對大型叢集開啟 Use_Kubelet 功能。
若要允許 Fluent Bit 將容器日誌傳送到 Amazon CloudWatch Logs,您必須向 Fluent Bit 授予 AWS Identity and Access Management (IAM) 許可。使用 Amazon EKS 時,有兩種方式可以授予 IAM 許可:
- 將政策附加到工作節點的 IAM 角色。
- 使用 IAM 服務帳戶角色。
如果將 IAM 許可授予 Fluent Bit,Fluent Bit 將能執行下列動作:
- logs:DescribeLogGroups
- logs:DescribeLogStreams
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
常見問題包括:
- Fluent Bit Pod 當機。
- Fluent Bit 未將日誌傳送至 CloudWatch。
- Fluent Bit Pod 傳回 CreateContainerConfigError。
解決方案
為服務帳戶設定 IAM 角色
使用 AWS 受管政策 CloudWatchAgentServerPolicy 為 amazon-cloudwatch 命名空間的 cloudwatch-agent 服務帳戶建立 IAM 角色。
1. 執行下列命令以設定環境變數:
export CLUSTER="clustername" export AWS_REGION="awsregion" export AWS_ACCOUNT="awsaccountid"
備註:將 "clustername"、"awsregion" 和 "awsaccountid" (包括引號) 替換為您自己的叢集名稱、AWS 區域和帳戶 ID。
2. 執行下列 eksctl 命令:
eksctl create iamserviceaccount \ --name cloudwatch-agent \ --namespace amazon-cloudwatch \ --cluster $CLUSTER \ --attach-policy-arn "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy" \ --approve \ --override-existing-serviceaccounts
如需容器洞察先決條件的詳細資訊,請參閱驗證先決條件。
設定 CloudWatch 代理程式以收集叢集指標並開啟容器洞察
1. 若要使用快速入門部署容器洞察,請執行下列命令:
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.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" (包括引號) 替換為您自己的叢集名稱和 AWS 區域。
上述命令會為 CloudWatch 代理程式和 Fluent Bit 建立命名空間、ClusterRole、ClusterRoleBinding 和 ConfigMap。
2. 執行該命令後,執行下列命令以建立 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
3. 執行下列命令以驗證 CloudWatch 代理程式是否已部署:
kubectl get pods -n amazon-cloudwatch
4. 完成後,CloudWatch 代理程式會建立日誌群組 /aws/containerinsights/Cluster_Name/performance。 然後,CloudWatch 代理程式會將效能日誌事件傳送到日誌群組。
疑難排解
Fluent Bit Pod 當機
1. 檢查 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
2. 驗證 cluster-info (ConfigMap 中儲存的 Fluent Bit 組態檔案) 是否正確且沒有語法錯誤。確定已設定所有叢集名稱和區域值。如需詳細資訊,請參閱 GitHub 網站上的 amazon-cloudwatch-container-insights。
Fluent Bit 未將日誌傳送至 CloudWatch
1. 確認輸出外掛程式已在 Fluent Bit 組態檔案中正確設定。若要檢查是否有任何資料傳送錯誤,請使用下列命令檢查 Fluent Bit Pod 日誌:
kubectl -n amazon-cloudwatch logs fluent_pod_name
2. 請確定 Fluent Bit Pod 具有將日誌串流至 CloudWatch 所需的 IAM 許可。由於 IAM 強制執行的 CloudWatchAgentServerPolicy,Amazon EKS 工作節點會將指標和日誌提交給 CloudWatch。有兩種方式可授予必要的 IAM 許可:
- 將政策新增至工作節點的 IAM 角色。
- 為叢集的服務帳戶建立 IAM 角色,並在其上加上政策。
如需詳細資訊,請參閱為服務帳戶設定 IAM 角色一節。
Fluent Bit Pod 在 CreateContainerConfigError 中卡住
如果 Pod 狀態為 CreateContainerConfigError,則執行下列命令以取得確切的錯誤訊息:
kubectl describe pod pod_name -n amazon-cloudwatch
在命令輸出的事件區段中,尋找如下所示的錯誤訊息:
Error syncing pod ("fluent-bit-xxxxxxx"), skipping: failed to "StartContainer" with CreateContain erConfigError: "configmap \"fluent-bit-config\" not found"
如果您看到此錯誤訊息,則很可能您並未替 Fluent Bit (fluent-bit-config) 建立 ConfigMap。再次執行安裝步驟以確實建立 ConfigMap。
相關資訊
相關內容
- 已提問 9 個月前lg...
- 已提問 4 個月前lg...
- 已提問 9 個月前lg...
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 2 年前