1

我在 K8s 集群中设置了 EFK 堆栈。目前 fluentd 正在从所有容器中抓取日志。

我希望它只从容器AB和.CD

如果我有一些前缀 asA-app我可以做类似下面的事情。

"fluentd-inputs.conf": "# HTTP input for the liveness and readiness probes
        <source>
          @type http
          port 9880
        </source>
        # Get the logs from the containers running in the node
        <source>
          @type tail
          path /var/log/containers/*-app.log // what can I put here for multiple different containers
          # exclude Fluentd logs
          exclude_path /var/log/containers/*fluentd*.log
          pos_file /opt/bitnami/fluentd/logs/buffers/fluentd-docker.pos
          tag kubernetes.*
          read_from_head true
          <parse>
            @type json
          </parse>
        </source>
        # enrich with kubernetes metadata
        <filter kubernetes.**>
          @type kubernetes_metadata
        </filter>
4

1 回答 1

1

要仅从特定 Pod 中抓取日志,您可以使用:

path /var/log/containers/POD_NAME_1*.log,/var/log/containers/POD_NAME_2*.log,.....,/var/log/containers/POD_NAME_N*.log

要从特定 Pod 中的特定容器中抓取日志,您可以使用:

path /var/log/containers/POD_NAME_1*CONTAINER_NAME*.log,/var/log/containers/POD_NAME_2*CONTAINER_NAME*.log,.....,/var/log/containers/POD_NAME_N*CONTAINER_NAME*.log

我创建了一个简单的示例来说明它是如何工作的。

web-1要从 Pod 的容器中抓取日志app-1并从 Pod 的所有容器中抓取日志app-2,您可以使用:

path /var/log/containers/app-1*web-1*.log,/var/log/containers/app-2*.log



$ kubectl logs -f fluentd-htwn5
...
2021-08-20 13:37:44 +0000 [info]: #0 starting fluentd worker pid=18 ppid=7 worker=0
2021-08-20 13:37:44 +0000 [info]: #0 [in_tail_container_logs] following tail of /var/log/containers/app-1_default_web-1-ae672aa1405b91701d130da34c54ab3106a8fc4901897ebbf574d03d5ca64eb8.log
2021-08-20 13:37:44 +0000 [info]: #0 [in_tail_container_logs] following tail of /var/log/containers/app-2-64c99b9f5b-tm6ck_default_nginx-cd1bd7617f04000a8dcfc1ccd01183eafbce9d0155578d8818b27427a4062968.log
2021-08-20 13:37:44 +0000 [info]: #0 [in_tail_container_logs] following tail of /var/log/containers/app-2-64c99b9f5b-tm6ck_default_frontend-1-e83acc9e7fc21d8e3c8a733e10063f44899f98078233b3238d6b3dc0903db560.log
2021-08-20 13:37:44 +0000 [info]: #0 fluentd worker is now running worker=0
...
于 2021-08-20T13:46:59.940 回答