Filebeat with ELK stack running in Kubernetes does not capture pod name in logs
我正在使用ELK堆栈(elasticsearch,logsash,kibana)在Kubernetes(minikube)环境中进行日志处理和分析。要捕获日志,我正在使用filebeat。日志成功地从filebeat传播到了Elasticsearch,并且可以在Kibana中查看。
我的问题是我无法获得实际的容器发布日志记录的容器名称。相反,我只得到正在收集日志文件的filebeat podname,而不是原始日志记录的pod的名称。
我可以从文件拍中获得的信息是(如在Kibana中查看的)
- beat.hostname:该字段的值是filebeat pod名称
- beat.name:值是文件拍子的pod名称
- 主机:值是filebeat窗格名称
我还可以在Kibana中查看/区分容器信息,这些信息从filebeat / logstash / elasticsearch中流过:
- 应用:值是{log-container-id} -json.log
- 来源:值为/hostfs/var/lib/docker/containers/{log-container-id}-json.log
如上所示,我似乎能够获得容器ID,但不能获得容器名称。
为缓解这种情况,我可能可以将pod-name嵌入到实际的日志消息中,然后从那里解析它,但是我希望有一种解决方案,在其中可以配置filebeat来发出实际的pod name。
现在有没有人如何配置filebeat(或其他组件)以在其日志中捕获kubernetes(minikube)pod名称?
下面列出了我当前的文件配置:
ConfigMap如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | apiVersion: v1 kind: ConfigMap metadata: name: filebeat namespace: logging labels: component: filebeat data: filebeat.yml: | filebeat.prospectors: - input_type: log tags: - host paths: -"/hostfs/var/log" -"/hostfs/var/log/*" -"/hostfs/var/log/*/*" exclude_files: - '\\.[0-9]$' - '\\.[0-9]\\.gz$' - input_type: log tags: - docker paths: - /hostfs/var/lib/docker/containers/*/*-json.log json: keys_under_root: false message_key: log add_error_key: true multiline: pattern: '^[[:space:]]+|^Caused by:' negate: false match: after output.logstash: hosts: ["logstash:5044"] logging.level: info |
DamemonSet如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | apiVersion: extensions/v1beta1 kind: DaemonSet metadata: name: filebeat namespace: logging spec: template: metadata: labels: component: filebeat spec: containers: - name: filebeat image: giantswarm/filebeat:5.2.2 imagePullPolicy: IfNotPresent resources: limits: cpu: 100m requests: cpu: 100m volumeMounts: - name: config mountPath: /etc/filebeat readOnly: true - name: hostfs-var-lib-docker-containers mountPath: /hostfs/var/lib/docker/containers readOnly: true - name: hostfs-var-log mountPath: /hostfs/var/log readOnly: true volumes: - name: config configMap: name: filebeat - name: hostfs-var-log hostPath: path: /var/log - name: hostfs-var-lib-docker-containers hostPath: path: /var/lib/docker/containers |
对于将来来这里的人们来说,它已经在filebeat处理器中提供了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | filebeat.prospectors: - type: log enabled: true paths: - /var/log/*.log - /var/log/messages - /var/log/syslog - type: docker containers.ids: -"*" processors: - add_kubernetes_metadata: in_cluster: true - drop_event: when: equals: kubernetes.container.name:"filebeat" |
helm图表默认值:https://github.com/helm/charts/blob/master/stable/filebeat/values.yaml
doc:https://www.elastic.co/guide/zh-CN/beats/filebeat/current/add-kubernetes-metadata.html
通过将一组特定的容器分配给一个命名空间,我已经实现了您想要的目标,现在可以使用命名空间,容器名称和容器名称的组合来查询我正在寻找的日志,生成的日志中也包含了该名称如您在此处看到的那样,通过文件节拍通过管道进行传输
免责声明:我是一位出色的开发者
filebeat尚不支持您要执行的操作,但是绝对可以,这是我们要付出的努力,因此可以预期将来的发行版将支持这种映射。
同时,我认为您的方法是正确的。您可以将所需的信息附加到日志中,以便将其保存在elasticsearch
中