
はじめに
k8sのログをグラフィカルにいい感じにしたかったので、Grafana Lokiを試してみた。
ログ基盤はEFKスタックが有名だが、軽量動作、Prometheusライク、かつより新しいオープンソースであるという理由で、Grafana Lokiを試してみることにした。
両者の比較については、以下参照。
https://grafana.com/docs/loki/latest/overview/comparisons/
インストール
環境
- Ubuntu 18.04
- ベアメタル
- proxyあり
- kubernetes v1.18.5
作業ログ
インストール方法は、以下の5通りの方法がある(2021/01/29時点)。
Instructions for different methods of installing Loki and Promtail.
- Install using Tanka (recommended)
- Install through Helm
- Install through Docker or Docker Compose
- Install and run locally
- Install from source
はじめに、推奨のTankaを使う方法を試してみたが、うまくいかなかった。(podが全てrunningにならなかった)
トラシューに時間がかかりそうだったため、Helmを使うやり方を先に試してみることにした。
Helmを使ったインストールは、とりあえずLokiとPromtailを動かすだけなら簡単にできた。
Install through Helmの手順に従って、インストールを実施。
$ helm repo add grafana https://grafana.github.io/helm-charts
"grafana" has been added to your repositories
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
--- snip ---
Grafanaのリポジトリはすでに登録されてた。
deploy-loki-stack-loki-promtail-grafana-prometheusのコマンドを実行し、Loki Stack (Loki, Promtail, Grafana, Prometheus)のインストールを実施。
$ k create ns loki
namespace/loki created
$ helm upgrade --install -n loki loki grafana/loki-stack --set grafana.ena
bled=true,prometheus.enabled=true,prometheus.alertmanager.persistentVolume.enabled=false,prometheus.server.persisten
tVolume.enabled=false
Release "loki" does not exist. Installing it now.
NAME: loki
LAST DEPLOYED: Fri Jan 29 06:34:32 2021
NAMESPACE: loki
STATUS: deployed
REVISION: 1
NOTES:
The Loki stack has been deployed to your cluster. Loki can now be added as a datasource in Grafana.
See http://docs.grafana.org/features/datasources/loki/ for more detail.
$ k -n loki get pod
NAME READY STATUS RESTARTS AGE
loki-0 1/1 Running 0 3h24m
loki-grafana-84f56465bc-6bd5n 1/1 Running 0 3h24m
loki-kube-state-metrics-5867478d69-qgmk5 1/1 Running 0 3h24m
loki-prometheus-alertmanager-995847787-nzmnf 2/2 Running 0 3h24m
loki-prometheus-node-exporter-kvqqr 0/1 Pending 0 3h24m
loki-prometheus-pushgateway-945fb9558-mfmfv 1/1 Running 0 3h24m
loki-prometheus-server-9f7bdb9b4-4r6z9 2/2 Running 0 3h24m
loki-promtail-z6vpx 1/1 Running 0 3h24m
$ $ k -n loki describe pod loki-prometheus-node-exporter-kvqqr
--- snip ---
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 4m16s (x141 over 3h25m) default-scheduler 0/1 nodes are available: 1 node(s) didn't have free ports for the requested pod ports.
node-exporterは、既に別のnamespaceで動いているので問題ない。
podのhostPortが重複するためpendingとなった。
Grafanaにログインするため、kubectl edit
でGrafanaのserviceのtypeをNodePortに変更する。
(Helmの変数で指定すべきだが、今回は試すだけなのでeditを使用)
Grafanaの初期ユーザーのログイン情報を確認。
$ kubectl -n loki get secret loki-grafana -o jsonpath='{.data.admin-user}' |base64 -d
admin
$ kubectl -n loki get secret loki-grafana -o jsonpath='{.data.admin-password}' |base64 -d
RUEmHKEj2jSMGmOmyAiBFnhMWugaM0GLjEzF7MjXn
Grafanaの設定なしにログのダッシュボードを見れることを期待したが、dashboardは存在しなかった。(data sourceはLokiとPrometheusのものが登録されていた)
なので、Grafana Labsのサイトにある以下のdashboardを使用してダッシュボードを作成。
以下、Logging Dashboard via Loki
の画像。
ログの検索が簡単にできるため、運用に使えそうと感じた。
Total count of stderr
とMatched word: "error" donut
は、Pie Chartのパネルを使っているため、別途Grafanaにプラグインをインストールする必要がある。
プラグインをインストールするために、Grafanaのpodでgrafana-cli plugins install grafana-piechart-panel
を実行したがproxy環境のせいで失敗。
なので、結局、GrafanaはPV(NFS)をマウントし、NFS上でプラグインモジュールをダウンロードしてプラグインをインストールした。
参考
- https://grafana.com/docs/loki/latest/overview/comparisons/
- https://speakerdeck.com/polar3130/lets-begin-cloud-native-logging-with-grafana-loki
- https://grafana.com/docs/loki/latest/installation/
- https://grafana.com/docs/loki/latest/installation/helm/
- https://grafana.com/grafana/plugins/grafana-piechart-panel/