如何过滤命名空间上的 filebeat 日志

发布于 2025-01-10 17:29:37 字数 868 浏览 0 评论 0原文

我有一个集群,我在其中运行 filebeat 作为恶魔服务,以下是相同的配置图。我只想从命名空间 abc 获取日志,但我仍然从所有命名空间获取日志,特别是我从占用 75% 空间的 filebeat 获取有关 filebeat 的日志。配置有问题吗?或者还有另一种更好的方法吗?或者其他方式停止从 filebeat 获取有关 filebeat 的日志?

kind: ConfigMap
metadata:
  name: filebeat-config
  namespace: kube-system
  labels:
    k8s-app: filebeat
data:
   filebeat.yml: |-
    filebeat.autodiscover:
      providers:
        - type: kubernetes
          node: ${NODE_NAME}
          hints.enabled: true
          hints.default_config:
            type: container
            paths:
              - /var/log/containers/*${data.kubernetes.container.id}.log
          templates:
            - condition:
                equals:
                  kubernetes.namespace: abc
    output.logstash:
      hosts: ['${LOGSTAH_HOST:elasticsearch}:${LOGSTASH_PORT:5044}']
    logging.level: "info"```

I have cluster where i am running filebeat as demon service and following is the configmap for the same. I want to get logs only from the namespace abc but I am still getting logs from all the name spaces, specially I am getting logs about filebeat from filebeat which is taking 75% of the space. Is anything wrong with configuration ? Or there is another better way to do it ? Or other way to stop getting the logs from filebeat about filebeat ?

kind: ConfigMap
metadata:
  name: filebeat-config
  namespace: kube-system
  labels:
    k8s-app: filebeat
data:
   filebeat.yml: |-
    filebeat.autodiscover:
      providers:
        - type: kubernetes
          node: ${NODE_NAME}
          hints.enabled: true
          hints.default_config:
            type: container
            paths:
              - /var/log/containers/*${data.kubernetes.container.id}.log
          templates:
            - condition:
                equals:
                  kubernetes.namespace: abc
    output.logstash:
      hosts: ['${LOGSTAH_HOST:elasticsearch}:${LOGSTASH_PORT:5044}']
    logging.level: "info"```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦慕雪 2025-01-17 17:29:37

这是因为您仍然有 hints.enabled: true 设置。

IMO 你只需要这个:

filebeat.autodiscover:
  providers:
    - type: kubernetes
      templates:
        - condition:
            equals:
              kubernetes.namespace: kube-system
          config:
            - type: container
              paths:
                - /var/log/containers/*-${data.kubernetes.container.id}.log
              exclude_lines: ["^\\s+[\\-`('.|_]"] 

或者另一种方法是使用 POD 上的注释来记录或不记录。

来自文档

Filebeat 支持根据提供商的提示进行自动发现。提示系统在 Kubernetes Pod 注释或具有前缀 co.elastic.logs 的 Docker 标签中查找提示。一旦容器启动,Filebeat 将检查它是否包含任何提示并为其启动正确的配置

。您还可以完全禁用默认设置,因此只会检索像 co.elastic.logs/enabled: true 这样注释的 Pod:

filebeat.autodiscover:
  providers:
    - type: kubernetes
      hints.enabled: true
      hints.default_config.enabled: false

It is because you have still hints.enabled: true setting.

IMO you only need this:

filebeat.autodiscover:
  providers:
    - type: kubernetes
      templates:
        - condition:
            equals:
              kubernetes.namespace: kube-system
          config:
            - type: container
              paths:
                - /var/log/containers/*-${data.kubernetes.container.id}.log
              exclude_lines: ["^\\s+[\\-`('.|_]"] 

Or the other way would be to work with annotations on you PODs which should be logged or not.

From the documentation

Filebeat supports autodiscover based on hints from the provider. The hints system looks for hints in Kubernetes Pod annotations or Docker labels that have the prefix co.elastic.logs. As soon as the container starts, Filebeat will check if it contains any hints and launch the proper config for it

E.g. you can also disable default settings entirely, so only Pods annotated like co.elastic.logs/enabled: true will be retrieved:

filebeat.autodiscover:
  providers:
    - type: kubernetes
      hints.enabled: true
      hints.default_config.enabled: false
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文