1、Loki 部署
本文不过多介绍,请参考官网:Install the monolithic Helm chart | Grafana Loki documentation
loki:
auth_enabled: false
commonConfig:
replication_factor: 1
storage:
type: 'filesystem' #you storage name
singleBinary:
replicas: 1
helm upgrade --values values.yaml loki --namespace=phx-sidecar grafana/loki
2、Promtail
本文不过多介绍,请参考官网:Install Promtail | Grafana Loki documentation
vim values.yaml
server:
log_level: info
log_format: logfmt
http_listen_port: 3101
clients:
# loki api地址
- url: http://loki.phx-sidecar:3100/loki/api/v1/push
positions:
filename: /run/promtail/positions.yaml
scrape_configs:
- job_name: kubernetes-pods
pipeline_stages:
- cri: {}
kubernetes_sd_configs:
- role: pod
relabel_configs:
# deploy 或者 pod中所采集的label
- action: keep
regex: true
source_labels:
- __meta_kubernetes_pod_annotation_prometheus_io_scrape # deploy 或者 pod中所采集的label
- action: drop
regex: .+
source_labels:
- __meta_kubernetes_pod_label_name
- source_labels:
- __meta_kubernetes_pod_label_app
target_label: __service__
- source_labels:
- __meta_kubernetes_pod_node_name
target_label: __host__
- action: drop
regex: ''
source_labels:
- __service__
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- action: replace
replacement: $1
separator: /
source_labels:
- __meta_kubernetes_namespace
- __service__
target_label: job
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: instance
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container_name
- replacement: /var/log/pods/*$1/*.log
separator: /
source_labels:
- __meta_kubernetes_pod_uid
- __meta_kubernetes_pod_container_name
target_label: __path__
limits_config:
tracing:
enabled: false
helm install promtail . -n phx-sidecar
3、应用示例
4、Grafana选择Prometheus数据源后查看