Fluent Bit & Fluentd

https://docs.fluentbit.io/manual/about/fluentd-and-fluent-bit
https://logz.io/blog/fluentd-vs-fluent-bit/

install fluentbit

官方提供兩種主流的安裝方式,這次的例子是container log -> fluent bit -> elasticsearch

  • Helm

Kustomize

第一步是建立namespace

kubectl create namespace logging

Helm Chart

依如往常的簡單,先新增fluent helm repo

helm repo add fluent https://fluent.github.io/helm-charts
kubectl create namespace logging
helm install --values=fluentbit-value.yaml -n logging fluent-bit fluent/fluent-bit

fluent bit config

我大多數input plugin 都是使用tail去拿到檔案資訊,行為就像是tail -f ,raw data是依照是哪種container而有所不同,像是docker和containerd,也因為來源的不同導致[INPUT]使用的paser設定也不同。

2021-01-22T03:27:45.253547129Z stdout F {"level":"info","app_id":"jeff-api","environment":"","hostname":"jys-api-server-749d876f57-6qxwh","grpc.start_time":1611286065,"grpc.service":"api.apiService","grpc.method":"EthereumCreateAddress","request_id":"56b69dd5-1234-12ab-987a-30f2311e2359","grpc.time_ms":26.612,"grpc.req":{},"grpc.resp":{"address_index":18,"address_hex":"0x4F97DAEC923BBB11a123d0123428984E522Cf750","created_at":"2021-01-22T03:27:45.227885267Z"},"access_log":true,"timestamp":1611286065,"graylog_level":6,"graylog_timestamp":1611286065.253,"message":"no message"}
https://stackoverflow.com/questions/40406928/kubernetes-save-json-logs-to-file-with-escaped-quotes-why

Fluentd

就像我一開始所提到,fluentd用於資訊收集和資料轉發,在高流量的網站,官方建議使用high-availability fluentd,去避免資料的遺失,官方提到三種可能性

  • At least once: 最少傳遞一次,在有問題的情況會有可能造成同樣的訊息兩次。
  • Exactly once: 每個訊息只會傳遞一次,這是最理想的狀態。
fluentd.conf in fluent/fluentd-kubernetes-daemonset:v1-debian-elasticsearch

fluent bit 設定

假設去tail /var/log/jeff-api-*.log 的資訊,如果是實體檔案有額外mount到ssd 或其他空間,記得在deployment加上mount 資訊(如下圖)

fluentd 設定

source 使用forward 接受所有port 24224來的訊息,然後使用copy 輸出到stdout和elasticsearch。

--

--

DevOps engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store