承接 Day 17(DCGM Exporter + Prometheus + Grafana 監控),今天要把 日誌 Logging 建立起來,透過 Loki + Promtail 收集 Isaac / Selkies 容器的日誌,集中管理並能在 Grafana 中檢索與關鍵字搜尋。
/var/log/containers/*.log
並打 Label 後送到 Loki。使用 Helm Chart 安裝:
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
kubectl create ns logging || true
helm upgrade --install loki grafana/loki-stack \
-n logging \
--set grafana.enabled=false \
--set prometheus.enabled=false \
--set fluent-bit.enabled=false
預設會裝 Loki(單副本)+ Promtail DaemonSet。
Promtail 預設會讀取 /var/log/containers
,並自動附上:
namespace
pod
container
node
為了讓 Isaac 與 Selkies 的日誌更容易區分,可以加上自訂 Label:
# promtail-additionalScrape.yaml
server:
log_level: info
clients:
- url: http://loki.logging:3100/loki/api/v1/push
positions:
filename: /tmp/positions.yaml
scrape_configs:
- job_name: kubernetes-pods
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_namespace]
target_label: namespace
- source_labels: [__meta_kubernetes_pod_name]
target_label: pod
- source_labels: [__meta_kubernetes_container_name]
target_label: container
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_name]
target_label: app
套用:
kubectl -n logging apply -f promtail-additionalScrape.yaml
若 Day 17 已有 Grafana,新增 Loki DataSource:
http://loki.logging:3100
進入 Explore → DataSource: Loki。
查詢 Isaac Pod 日誌:
{namespace="robotics", container="isaac"}
查詢 Selkies 日誌:
{namespace="robotics", container="selkies"}
搭配 Prometheus 度量 → 在同一儀表板同時顯示 GPU 使用率 + 錯誤日誌。
|= "error"
、|~ "WARN|ERROR"
)。面倒くさいな