當我將 Fluent Bit 與 Amazon EKS 的 Container Insights 整合時,要如何疑難排解設定問題?

2 分的閱讀內容
0

我想要在將 Fluent Bit 與 Amazon Elastic Kubernetes Service (Amazon EKS) 的 Amazon CloudWatch Container Insights 整合時疑難排解設定問題。

簡短描述

**注意事項:**最佳實務是使用 Fluent Bit 而非 Fluentd。如需詳細資訊,請參閱 Send logs to CloudWatch Logs

若要允許 Fluent Bit 將容器日誌傳遞至 CloudWatch Logs,您必須授予 AWS Identity and Access Management (IAM) 對 Fluent Bit 的權限。如需詳細資訊,請參閱 Verify prerequisites

若要透過 Fluent Bit 使用 Container Insights,請設定服務帳戶的 IAM 角色 (IRSA),然後在您的 EKS 叢集中部署 Container Insights。

解決方法

透過 Fluent Bit 設定 Container Insights

使用 CloudWatchAgentServerPolicy AWS 受管政策,以建立 cloudwatch-agentfluent-bit 服務帳戶。

請完成下列步驟:

  1. 執行下列命令以設定環境變數:

    export CLUSTER=clustername
    export AWS_REGION=awsregion

    **注意事項:**以您的叢集名稱取代 clustername,並以 AWS 區域取代 awsregion

  2. 執行下列 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
  3. 執行下列 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
  4. 若要使用快速入門來部署 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 建立 ClusterRoleClusterRoleBindingConfigMapDaemonSet

  5. 執行下列命令,驗證 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 日誌中的錯誤訊息,請完成下列步驟:

  1. 執行下列命令,尋找 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 正確無誤,且沒有任何語法錯誤。

  3. 確認所有叢集名稱和區域值已設定完成。如需詳細資訊,請參閱 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 擁有必要的 IAM 權限,可為 CloudWatch 建立日誌群組和串流日誌。您必須將 CloudWatchAgentServerPolicy IAM 政策連接至 fluent-bit 服務帳戶中註解的 IAM 角色。
    若您使用 IRSA,您必須將 IAM 角色連接至工作節點。如需詳細資訊,請參閱如何對 Amazon EKS 中的 IRSA 錯誤進行疑難排解?

若您找不到特定應用程式日誌,請確認您的應用程式可以執行。然後,確認應用程式是否能產生其他類型的日誌。若應用程式可以執行並產生日誌,請檢查 fluent-bit Pod 日誌,確認是否已將特定錯誤傳送至 CloudWatch。

Fluent Bit Pods 卡在 CreateContainerConfigError 狀態

執行下列命令以取得確切的錯誤訊息:

kubectl describe pod pod_name -n amazon-cloudwatch

在命令輸出的事件區段中,尋找類似下列內容的錯誤訊息:

Error syncing pod ("fluent-bit-xxxxxxx"), skipping: failed to "StartContainer" with CreateContainerConfigError: "configmap \"fluent-bit-config\" not found"

若您看到前述的錯誤訊息,表示缺少 Fluent Bit (fluent-bit-config) 的 ConfigMap。重複本文章透過 Fluent Bit 設定 Container Insights 區段的步驟 4。

相關資訊

設定 CloudWatch 代理程式來收集叢集指標

快速入門 CloudWatch 代理程式和 Fluent Bit

啟動 GitHub 網站的偵錯日誌記錄

AWS 官方
AWS 官方已更新 10 個月前