4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Grafana Lokiを軽く試してみた

Posted at
https://github.com/grafana/loki/blob/master/README.md

はじめに

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.

はじめに、推奨の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の画像。

grafana_1.png

grafana_2.png

grafana_3.png

ログの検索が簡単にできるため、運用に使えそうと感じた。

Total count of stderrMatched word: "error" donutは、Pie Chartのパネルを使っているため、別途Grafanaにプラグインをインストールする必要がある。
プラグインをインストールするために、Grafanaのpodでgrafana-cli plugins install grafana-piechart-panelを実行したがproxy環境のせいで失敗。
なので、結局、GrafanaはPV(NFS)をマウントし、NFS上でプラグインモジュールをダウンロードしてプラグインをインストールした。

参考

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?