10
6

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 5 years have passed since last update.

Grafana LokiをMinikubeで試す

Last updated at Posted at 2019-08-18

Grafana LokiをHelmチャートを使ってインストールする。

コンポーネント バージョン
Minikube v1.3.1
Kubernetes v1.15.2
Helm v2.14.4
loki-stackチャート 0.15.0
Grafanaチャート 3.8.1
Grafana 6.2.5

準備

Minikubeを起動する。

minikube start

Minikubeでingressのアドオンを有効にする。

minikube addons enable ingress

MinikubeのIPアドレスを確認する。

minikube ip

/etc/hostsにMinikubeのIPを追記する。各コンポーネントへのIngress経由でのアクセスをパスで分けようとすると、パスのリライトやリダイレクトの整合性をとるのが難しいので、仮想ホストを分けた方が楽。

/etc/hosts
192.168.99.141  grafana.minikube

Grafana LokiとGrafanaをデプロイする先のNamespaceを作成する。

kubectl create ns monitoring

helmを初期化し、クラスターにtillerをデプロイする。

helm init

Grafana Loki

Helmリポジトリを追加する。

helm repo add loki https://grafana.github.io/loki/charts
helm repo update

Lokiのチャートを確認する。

$ helm search loki
NAME           	CHART VERSION	APP VERSION	DESCRIPTION
loki/loki      	0.13.0       	0.0.1      	Loki: like Prometheus, but for logs.
loki/loki-stack	0.15.0       	0.0.1      	Loki: like Prometheus, but for logs.
loki/promtail  	0.11.0       	0.0.1      	Responsible for gathering logs and sending them to Loki
$

loki-stackがまとめてインストールするためのチャートで、loki、promtailは個別にインストールするためのチャート。valuesを確認すると、loki-stackのほうはvaluesで設定できるところが少ない(PersistentVolumeも設定できない)ので、いろいろ設定したい場合はそれぞれ個別にインストールした方がよさそう。今回はloki-stackでやってみる。

$ helm inspect values loki/loki-stack
loki:
  enabled: true

promtail:
  enabled: true

grafana:
  enabled: false
  sidecar:
    datasources:
      enabled: true
  image:
    tag: 6.3.0-beta2

prometheus:
  enabled: false
  server:
    fullnameOverride: prometheus-server

$

デフォルトのままインストールする。

コマンド
helm upgrade --install loki --namespace=monitoring loki/loki-stack
実行例
$ helm upgrade --install loki --namespace=monitoring loki/loki-stack
Release "loki" does not exist. Installing it now.
NAME:   loki
LAST DEPLOYED: Wed Aug 14 15:56:32 2019
NAMESPACE: monitoring
STATUS: DEPLOYED

RESOURCES:
==> v1/ClusterRole
NAME                       AGE
loki-promtail-clusterrole  0s

==> v1/ClusterRoleBinding
NAME                              AGE
loki-promtail-clusterrolebinding  0s

==> v1/ConfigMap
NAME                  DATA  AGE
loki-loki-stack-test  1     0s
loki-promtail         1     0s

==> v1/DaemonSet
NAME           DESIRED  CURRENT  READY  UP-TO-DATE  AVAILABLE  NODE SELECTOR  AGE
loki-promtail  1        1        0      1           0          <none>         0s

==> v1/Pod(related)
NAME                 READY  STATUS             RESTARTS  AGE
loki-0               0/1    ContainerCreating  0         0s
loki-promtail-9zwnd  0/1    ContainerCreating  0         0s

==> v1/Role
NAME           AGE
loki           0s
loki-promtail  0s

==> v1/RoleBinding
NAME           AGE
loki           0s
loki-promtail  0s

==> v1/Secret
NAME  TYPE    DATA  AGE
loki  Opaque  1     0s

==> v1/Service
NAME           TYPE       CLUSTER-IP    EXTERNAL-IP  PORT(S)   AGE
loki           ClusterIP  10.97.36.183  <none>       3100/TCP  0s
loki-headless  ClusterIP  None          <none>       3100/TCP  0s

==> v1/ServiceAccount
NAME           SECRETS  AGE
loki           1        0s
loki-promtail  1        0s

==> v1/StatefulSet
NAME  READY  AGE
loki  0/1    0s

==> v1beta1/PodSecurityPolicy
NAME           PRIV   CAPS      SELINUX           RUNASUSER  FSGROUP    SUPGROUP  READONLYROOTFS  VOLUMES
loki           false  RunAsAny  MustRunAsNonRoot  MustRunAs  MustRunAs  true      configMap,emptyDir,persistentVolumeClaim,secret
loki-promtail  false  RunAsAny  RunAsAny          RunAsAny   RunAsAny   true      secret,configMap,hostPath


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.

$

Grafana

Grafanaのチャートを確認する。

$ helm search grafana
NAME          	CHART VERSION	APP VERSION	DESCRIPTION
stable/grafana	3.8.1        	6.2.5      	The leading tool for querying and visualizing time series...
$

valuesファイルを作成する。

grafana-values.yaml
ingress:
  enabled: true
  hosts:
    - grafana.minikube
persistence:
  enabled: true
  storageClassName: "standard"
  size: 1Gi

Grafanaをインストールする。

コマンド
helm upgrade --install grafana --namespace monitoring -f grafana-values.yaml stable/grafana
実行例
$ helm upgrade --install grafana --namespace monitoring -f grafana-values.yaml stable/grafana
Release "grafana" does not exist. Installing it now.
NAME:   grafana
LAST DEPLOYED: Wed Aug 14 16:05:23 2019
NAMESPACE: monitoring
STATUS: DEPLOYED

RESOURCES:
==> v1/ClusterRole
NAME                 AGE
grafana-clusterrole  0s

==> v1/ClusterRoleBinding
NAME                        AGE
grafana-clusterrolebinding  0s

==> v1/ConfigMap
NAME          DATA  AGE
grafana       1     0s
grafana-test  1     0s

==> v1/PersistentVolumeClaim
NAME     STATUS  VOLUME                                    CAPACITY  ACCESS MODES  STORAGECLASS  AGE
grafana  Bound   pvc-185e05f7-98e2-45c8-9581-b73e3c7ddf70  1Gi       RWO           standard      0s

==> v1/Pod(related)
NAME                      READY  STATUS    RESTARTS  AGE
grafana-6f7f8fd676-hfxd5  0/1    Init:0/1  0         0s

==> v1/Role
NAME          AGE
grafana-test  0s

==> v1/RoleBinding
NAME          AGE
grafana-test  0s

==> v1/Secret
NAME     TYPE    DATA  AGE
grafana  Opaque  3     0s

==> v1/Service
NAME     TYPE       CLUSTER-IP      EXTERNAL-IP  PORT(S)  AGE
grafana  ClusterIP  10.101.117.247  <none>       80/TCP   0s

==> v1/ServiceAccount
NAME          SECRETS  AGE
grafana       1        0s
grafana-test  1        0s

==> v1beta1/Ingress
NAME     HOSTS             ADDRESS  PORTS  AGE
grafana  grafana.minikube  80       0s

==> v1beta1/PodSecurityPolicy
NAME          PRIV   CAPS      SELINUX   RUNASUSER  FSGROUP   SUPGROUP  READONLYROOTFS  VOLUMES
grafana       false  RunAsAny  RunAsAny  RunAsAny   RunAsAny  false     configMap,emptyDir,projected,secret,downwardAPI,persistentVolumeClaim
grafana-test  false  RunAsAny  RunAsAny  RunAsAny   RunAsAny  false     configMap,downwardAPI,emptyDir,projected,secret

==> v1beta1/Role
NAME     AGE
grafana  0s

==> v1beta1/RoleBinding
NAME     AGE
grafana  0s

==> v1beta2/Deployment
NAME     READY  UP-TO-DATE  AVAILABLE  AGE
grafana  0/1    1           0          0s


NOTES:
1. Get your 'admin' user password by running:

   kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

2. The Grafana server can be accessed via port 80 on the following DNS name from within your cluster:

   grafana.monitoring.svc.cluster.local

   From outside the cluster, the server URL(s) are:
     http://grafana.minikube


3. Login with the password from step 1 and the username: admin

$

上記出力に従い、adminのパスワードを確認しておく。

Lokiの設定

以下のURLからGrafanaにアクセスしてログインする。

データソースとしてLokiを設定する。

image.png

Exploreからログを確認する。

image.png

参考リンク

10
6
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
10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?