# 系統 Log 資料

任何系統運作後，都會產出**系統記錄Log**，`Kubernetes Container`環境下產出的`log`，經過標準輸出`stdout`後，存放於`K8s worker node`的目錄下`/var/log/../*.log`。\
每個 **node** 都個別執行不同的 **AP應用服務**，並且隨著`Pod`的變動，**Log屬性與目錄**相對會隨著變動。\
因此需要透過**Log架構**來特別處理此事。

### Log架構

![](https://2429754843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNvFlJVNWRY5EiiMb6a%2F-LqGxdkqth9gACNqQOuW%2F-LqH0IO08SvtSR68jxu5%2Fimage.png?alt=media\&token=91c619f4-ebed-458a-b9a4-7c95b74e1aac)

**K8s** 叢集環境中，`worker node`會隨著應用需求而異動、增減，因此我們在每個`worker node`上藉由`DaemonSet`方式來部署圖中的`logging-agent-pod`。

上述只是收集`Log`的開端，收集`Log`後我們還需要一套系統作為收集、分析、儲存、資料圖表等等。目前市面上這類系統，除了 **ELK** 之外，仍有其他眾多方案，如果是初期導入使用，建議可以先從 **ELK** 方面著手，等上手後如有更多不同因素需求面向，可以在評估其他可行方案。

### ELK簡略

**ELK** 是三項開源方案的簡稱：`Elasticsearch`、`Logstash` 和 `Kibana`\
現在官方有個新名稱：`Elastic Stack`

* **Elasticsearch**：簡稱 **ES**，是一套以Lucene基礎的搜尋引擎，基於Json格式而開發與應用，提供Web接口存放`Log`資料。**ES** 本身支援分散式架構，引擎是透過Java語言開發的，所以對Java based的服務運行需要有一定的學習與瞭解。
* **Logstash**：此作為收集`Log`的`logging-agent`角色，能夠採集、分析、過濾和傳送資料到 **ES** 或其他目的地。本身支援`Grok`語法可將非結構化`log`數據進行分析與組成結構化，例如`IP`地址解碼出地理坐標，匿名化或排除敏感字段，並簡化整體處理過程。
* **Kibana**：此為 **ES** 的開源數據圖表化方案。它在 **ES** 集群上所存在的`Log`索引內容之中提供圖表化功能。

抱歉，我不是故意要擾亂視聽......\
因為，`ELK`名稱比較眾人所知......因此借題做開場說明。\
回到環境中，下一篇我要用`EFK`作為 **K8s** 環境上`Log`收集的主要系統。\
F = Fluent Bit

![](https://2429754843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNvFlJVNWRY5EiiMb6a%2F-LqGxdkqth9gACNqQOuW%2F-LqHA5bXuONcgYrRjY6T%2Fimage.png?alt=media\&token=5176ea3c-21b4-47c5-ac78-f210156cd3e0)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fufu.gitbook.io/kk8s/task-memory/17.system-log-info.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
