如何获取log fluentd的特定名称空间

发布于 2025-02-07 18:31:42 字数 1113 浏览 3 评论 0原文

因此,我想从特定的名称空间获取日志并将其发送到OpenSearch,因此我没有线索,所以我决定尝试这样做:

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    k8s-app: fluentd-logging
  name: simple-fluentd-configmap
  namespace: fluent-log
data:
  fluent.conf: |
    <match fluent.**>  
      @type null   
    </match>     
    <source> 
      @type tail
      path /var/log/pods/containers*.log
      pos_file /var/log/containers.pos
      format none
    <filter **>
        @type record_modifier
        remove_keys "container_id,source"
        @type parser
        key_name log
        hash_value_field log
        <parse>
          @type json
        </parse>
    </filter>
    <match kubernetes.var.log.containers.**access**.log>
    @type opensearch
    port 443
    logstash_format false
    scheme https
    ssl_verify false
    </match>
    <match kubernetes.var.log.containers.**balance**.log>
    @type opensearch
    port 443
    logstash_format false
    scheme https
    ssl_verify false
    </match>

因此,问题是如何使其根据来自从中的名称空间发送特定的日志kubernetes?

So I wanted to fetch logs from a specific namespace and send them to opensearch, so I didn't get a clue so I decided to try to make it like this:

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    k8s-app: fluentd-logging
  name: simple-fluentd-configmap
  namespace: fluent-log
data:
  fluent.conf: |
    <match fluent.**>  
      @type null   
    </match>     
    <source> 
      @type tail
      path /var/log/pods/containers*.log
      pos_file /var/log/containers.pos
      format none
    <filter **>
        @type record_modifier
        remove_keys "container_id,source"
        @type parser
        key_name log
        hash_value_field log
        <parse>
          @type json
        </parse>
    </filter>
    <match kubernetes.var.log.containers.**access**.log>
    @type opensearch
    port 443
    logstash_format false
    scheme https
    ssl_verify false
    </match>
    <match kubernetes.var.log.containers.**balance**.log>
    @type opensearch
    port 443
    logstash_format false
    scheme https
    ssl_verify false
    </match>

So the question is how to make it send specific logs based on namespace from kubernetes?

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

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

发布评论

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

评论(1

贩梦商人 2025-02-14 18:31:42

配置中的第二个匹配子句(从kubernetes.var.log ...开始的一个开始,应包含名称空间,因此您可以根据特定的名称空间过滤并决定如何处理这些特定日志。

如果出于任何原因,群集中的日志路径不包含其路径中的命名空间,则还可以使用 kubernetes 插件。
它将用与群集相关的元数据丰富您的日志,并允许您提取源自源自的名称空间日志并相应地处理它们。

The second match clause in your configuration (the one starting with kubernetes.var.log...) should contain the namespace, and therefore you can filter based on specific namespaces and decide how to handle those specific logs.

If, for any reason, the log path in your cluster does not contain the namespace in its path, you can also use the kubernetes plugin.
It will enrich your logs with metadata relevant to the cluster, and allow you to extract the namespace logs originated from and deal with them accordingly.

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