Loki收集应用日志

搭建前提:loki需搭建好

简要说明:搭建Pod应用时,将日志收集路径挂载出来。同时sidecar容器中也挂载此收集路径,将其挂载到empty dir上,将收集的日志发送到loki上。可以使用fluentd fluent-bit和promtail;这里使用promtail。

部署文件如下

apiVersion: v1
kind: ConfigMap
metadata:
  name: promtail-sidecar-conf
  labels:
    app: promtail-sidecar
data:
  promtail.yaml: |
    scrape_configs:
      - job_name: system          
        entry_parser: raw          
        static_configs:
          - targets:
              - localhost
            labels:
              job: promtail              
              tag: test               
              __path__: /var/log/test/*.log   #收集日志路径
---	 
apiVersion: apps/v1  
kind: Deployment  
metadata:
  name: test1
spec:
  template:
    metadata:
      name: test1
spec:
  containers:        
  - name: test-logger         
    image: xxxx/library/centos:c7-sp    #测试镜像
    volumeMounts:
      - name: log
        mountPath: /var/log/test
  - name: promtail          
    image: xxxx/library/grafana/promtail:v1.0.0           #promtail使用镜像
    args:
      - "-config.file=/etc/promtail/promtail.yaml"            #promtail配置文件路径
      - "-client.url=http://loki-test.monitor:3100/loki/api/v1/push"  #loki服务端
    volumeMounts:
    - name: config
      mountPath: /etc/promtail
    - name: run
      mountPath: /run/promtail
    - name: log
      mountPath: /var/log/test
  volumes:
  - name: log
    emptyDir: {}
  - name: config
    configMap:
      name: promtail-sidecar-conf
  - name: run
    hostPath:
      path: /run/promtail

你可能感兴趣的:(Loki)