Loki-stack

90

部署

  • 首先添加 Loki 的 Chart 仓库:

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

  • 获取 loki-stack 的 Chart 包并解压:

helm pull grafana/loki-stack --untar --version 2.9.10 #目前最新的

  • 编辑values文件,选择安装什么组件

  • 这边是安装一套loki-stack(loki+promtail+Prometheus+grafana+alertmanager+node-exproter+pushgateway+kube-state-metrics)

  • 需要提前安装storage (我这边是nfs-storage )

test_pod:
  enabled: true
  image: bats/bats:1.8.2
  pullPolicy: IfNotPresent

loki:
  enabled: true
  persistence:
    enabled: true
    storageClassName: nfs-storage
    accessModes:
      - ReadWriteOnce
    size: 10Gi
  isDefault: true
  url: http://{{(include "loki.serviceName" .)}}:{{ .Values.loki.service.port }}
  readinessProbe:
    httpGet:
      path: /ready
      port: http-metrics
    initialDelaySeconds: 45
  livenessProbe:
    httpGet:
      path: /ready
      port: http-metrics
    initialDelaySeconds: 45
  datasource:
    jsonData: "{}"
    uid: ""


promtail:
  enabled: true
  config:
    logLevel: info
    serverPort: 3101
    clients:
      - url: http://{{ .Release.Name }}:3100/loki/api/v1/push


grafana:
  enabled: true
  persistence:
    enabled: true
    storageClassName: nfs-storage
    accessModes:
      - ReadWriteOnce
    size: 10Gi
  sidecar:
    datasources:
      label: ""
      labelValue: ""
      enabled: true
      maxLines: 1000
  image:
    tag: 8.3.5

prometheus:
  enabled: true
  isDefault: false
  url: http://{{ include "prometheus.fullname" .}}:{{ .Values.prometheus.server.service.servicePort }}{{ .Values.prometheus.server.prefixURL }}
  datasource:
    jsonData: "{}"




# proxy is currently only used by loki test pod
# Note: If http_proxy/https_proxy are set, then no_proxy should include the
# loki service name, so that tests are able to communicate with the loki
# service.
proxy:
  http_proxy: ""
  https_proxy: ""
  no_proxy: ""

安装

[root]# kubectl create ns logging
[root]# helm upgrade --install loki -n logging -f values.yaml . 
Release "loki" does not exist. Installing it now.
NAME: loki
LAST DEPLOYED: Thu Jul 13 14:29:44 2023
NAMESPACE: logging
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.

查看

[k8s-01 14:40:16 /home/loki-stack]
[root]#  kubectl get pods -n logging
NAME                                           READY   STATUS    RESTARTS   AGE
loki-0                                         1/1     Running   0          13m
loki-grafana-65d7cb56b4-dhmxs                  2/2     Running   0          13m
loki-kube-state-metrics-775c548766-d4vsw       1/1     Running   0          2m19s
loki-prometheus-alertmanager-57f5cd87f-gxsfk   2/2     Running   0          13m
loki-prometheus-node-exporter-hfvck            1/1     Running   0          13m
loki-prometheus-node-exporter-n4zmn            1/1     Running   0          13m
loki-prometheus-node-exporter-p8cwp            1/1     Running   0          13m
loki-prometheus-pushgateway-7b8fc5d979-jg8vs   1/1     Running   0          13m
loki-prometheus-server-74878cb776-ldsw6        2/2     Running   0          13m
loki-promtail-rxwzj                            1/1     Running   0          13m
loki-promtail-wtkm6                            1/1     Running   0          13m
loki-promtail-xg55c                            1/1     Running   0          13m

  • 这里我们为 Grafana 设置的 NodePort 类型的 Service:

[k8s-01 14:44:12 /home/loki-stack]
[root]#  kubectl get svc -n logging
NAME                            TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
loki                            ClusterIP   10.96.1.118   <none>        3100/TCP       15m
loki-grafana                    NodePort    10.96.1.188   <none>        80:31266/TCP   15m
loki-headless                   ClusterIP   None          <none>        3100/TCP       15m
loki-kube-state-metrics         ClusterIP   10.96.0.211   <none>        8080/TCP       15m
loki-memberlist                 ClusterIP   None          <none>        7946/TCP       15m
loki-prometheus-alertmanager    ClusterIP   10.96.2.100   <none>        80/TCP         15m
loki-prometheus-node-exporter   ClusterIP   None          <none>        9100/TCP       15m
loki-prometheus-pushgateway     ClusterIP   10.96.2.2     <none>        9091/TCP       15m
loki-prometheus-server          ClusterIP   10.96.0.170   <none>        80/TCP         15m
[k8s-01 14:44:57 /home/loki-stack]
[root]#

可以通过 NodePort 端口 31266 访问 Grafana,使用下面的命令获取 Grafana 的登录密码:

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

我们使用 Helm 安装的 Promtail 默认已经帮我们做好了配置,已经针对 Kubernetes 做了优化.