一、部署loki-stack
0、介绍
架构介绍:
grafana/loki:单体 loki,性能支持线性伸缩;
grafana/loki-stack:loki 的工具栈,包括 loki、promtail、grafana 等,缺点是没有提供对接外部 MinIO 的配置;
grafana/loki-distributed:微服务模式的 loki 集群,性能上限最高,推荐生产环境使用;
组件介绍:
loki: 日志记录引擎,负责存储日志和处理查询
promtail: 代理,负责收集日志并将其发送给 loki
grafana: UI 界面
1、添加helm repo
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
2、自定义values部署
helm search repo loki-stack
helm pull grafana/loki-stack --version=2.10.2 --untar
helm --create-namespace loki -n loki install ./loki-stack -f ./values.yaml
模板1:精简安装
cat values.yaml
loki:
persistence:
enabled: true
size: 10Gi
accessModes:
- ReadWriteOnce
commonConfig:
replication_factor: 1
storage:
type: 'filesystem'
config:
limits_config:
max_query_length: 0h
service:
type: LoadBalancer
singleBinary:
replicas: 1
promtail:
enabled: false
模板2:兼容污点更新
kubectl label node node01 platform.chandz.com/infra=true
kubectl taint node node01 platform.chandz.com/infra=true:NoSchedule
修改value并更新
loki:
persistence:
enabled: true
size: 10Gi
accessModes:
- ReadWriteOnce
commonConfig:
replication_factor: 1
storage:
type: 'filesystem'
config:
limits_config:
max_query_length: 0h
service:
type: LoadBalancer
tolerations:
- key: "platform.chandz.com/infra"
operator: "Exists"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: platform.chandz.com/infra
operator: In
values:
- "true"
singleBinary:
replicas: 1
promtail:
enabled: false
helm upgrade --install loki -n loki ./loki-stack -f values.yaml
模板3:全部组件安装
loki:
enable: true
service:
type: NodePort
tolerations:
- key: "platform.chandz.com/infra"
operator: "Exists"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: platform.chandz.com/infra
operator: In
values:
- "true"
persistence:
enabled: true
size: 5Gi
accessModes:
- ReadWriteOnce
storageClassName: local-path
promtail:
enabled: true
grafana:
enabled: true
service:
type: NodePort
tolerations:
- key: "platform.chandz.com/infra"
operator: "Exists"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: platform.chandz.com/infra
operator: In
values:
- "true"
persistence:
type: pvc
enabled: false
storageClassName: local-path
accessModes:
- ReadWriteOnce
size: 5Gi
高可用改造(测试中)
loki-stack/values.yaml
loki:
replicas: 3
persistence:
enabled: true
size: 10Gi
accessModes:
- ReadWriteOnce
commonConfig:
replication_factor: 3
storage:
type: 'filesystem'
config:
limits_config:
max_query_length: 0h
storage_config:
aws:
s3: http://QeytJ4j0u6Kodh4ki6Ra:ctrCLm0XRWmhZuv2flt5Wgf9QaGpNGFOXoMBCFxT@192.168.86.21:31388
bucketnames: loki-stack-data
s3forcepathstyle: true
boltdb_shipper:
shared_store: s3
schema_config:
configs:
- from: 2024-03-30
store: boltdb-shipper
object_store: aws
schema: v12
index:
prefix: loki_index_
period: 24h
compactor:
shared_store: aws
working_directory: /data/loki/boltdb-shipper-compactor
ingester:
lifecycler:
ring:
replication_factor: 3
service:
type: LoadBalancer
singleBinary:
replicas: 3
promtail:
enabled: true
分布式部署参考:
https://imwang.top/2023/03/03/loki-with-minio.html
https://www.cnblogs.com/hahaha111122222/p/16407693.html
3、配置grafana对接loki
1、获取grafana密码
kubectl get secret --namespace loki loki-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo