简体   繁体   English

配置 fluentd 以在 Kubernetes 集群中选择 Jenkins 作业/应用程序日志

[英]Configure fluentd to pick Jenkins job/application logs in a kubernetes cluster

I have a kubernetes cluster in which I have jenkins and spinnaker pods up and running.我有一个 kubernetes 集群,其中启动并运行了 jenkins 和 spinnaker pod。 I need to implement a logging mechanism which collects and sends logs to splunk server.我需要实现一个日志记录机制来收集日志并将其发送到 splunk 服务器。 I chose to do so using fluentd.我选择使用 fluentd 来实现。 I have deployed a daemon set of fluentd to run on each node and collect logs from each node and send to splunk server.我已经部署了一套 fluentd 守护进程在每个节点上运行,并从每个节点收集日志并发送到 splunk 服务器。

It is working fine for logs that we see using "kubectl logs" or logs that come to stdout.对于我们使用“kubectl 日志”或标准输出的日志看到的日志,它工作正常。 However, I need to pick logs from a jenkins job (Console output of a jenkins job build).但是,我需要从 jenkins 作业中选择日志(jenkins 作业构建的控制台输出)。 These logs are not going to std out of the node, and are stored at /var/jenkins_home/jobs/XXX/builds/<buildno > inside the container storage which is not directly accessible to fluentd for log collection.这些日志不会从节点中输出,而是存储在容器存储中的/var/jenkins_home/jobs/XXX/builds/<buildno > 中,而 fluentd无法直接访问该容器以进行日志收集。

I am open for any kind of solution to this problem.我对这个问题的任何解决方案持开放态度。 Please suggest.请建议。

Fluentd dont have any feature like this in case of kubernetes as kubernetes will not allow direct access to any third party plugin to read the data from container.在 kubernetes 的情况下,Fluentd 没有任何这样的功能,因为 kubernetes 不允许直接访问任何第三方插件来从容器读取数据。 For STDOUT log also first processed by kubernetes and kept at node level.对于 STDOUT 日志,也首先由 kubernetes 处理并保存在节点级别。 After that you will be able to see.之后你就可以看到了。

As a workaround you can follow below link.作为解决方法,您可以按照以下链接操作。

Kubernetes - How to read logs that are written to files in pods instead of stdout/stderr? Kubernetes - 如何读取写入 pod 中的文件而不是 stdout/stderr 的日志?

Long way:很长的路要走:

  1. Add hostpath directory volume to a jenkins deployment: https://kubernetes.io/docs/concepts/storage/volumes/#hostpathhostpath目录卷添加到 jenkins 部署: https ://kubernetes.io/docs/concepts/storage/volumes/#hostpath
  2. Run a separate FluentBit/Fluentd to collect logs from that directory.运行单独的 FluentBit/Fluentd 以从该目录收集日志。 Both of them support putting path in a dedicated field in a log or to a tag: https://docs.fluentbit.io/manual/pipeline/inputs/tail它们都支持将路径放在日志或标签的专用字段中: https : //docs.fluentbit.io/manual/pipeline/inputs/tail
  3. Use path/tag to parse-out job name and organize the destination storage accordingly.使用路径/标签来解析作业名称并相应地组织目标存储。 Or just leave it as is and filter on the view.或者保持原样并过滤视图。

Short way: Use jenkins kubernetes plugin to run each job as a separate pod: https://plugins.jenkins.io/kubernetes/ .简短的方法:使用 jenkins kubernetes 插件将每个作业作为单独的 pod 运行: https : //plugins.jenkins.io/kubernetes/。 Then it will get collected and tagged by a daemonset separately.然后它将被单独的守护进程收集和标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins 管道作业不断在 kubernetes 集群内创建 pod - Jenkins pipeline job keeps on creating pods inside kubernetes cluster 在 kubernetes 集群上使用 docker 命令运行 Jenkins 作业失败“docker:未找到” - Running Jenkins job with docker command on kubernetes cluster fails "docker: not found" Jenkins在Kubernetes集群上的安装 - Jenkins Installation On Kubernetes Cluster 在Kubernetes集群中部署Jenkins - Deploy Jenkins in Kubernetes cluster 是否可以配置Jenkins构建作业以从本地maven存储库中选择maven工件 - Is it possible to configure a Jenkins Build Job to pick maven artifacts from local maven repository 配置Jenkins作业以从SVN中选择应用程序和中继/标记/分支 - Configure a Jenkins job to select an application and trunk/tags/branches from SVN 如何在 Jenkins maven 作业中从外部配置 application.properties? - How to configure the application.properties externally in the Jenkins maven job? Jenkins 在 kube.netes 集群上执行的作业在 jnlp 图像而不是指定的图像上运行 - Jenkins job executed on kubernetes cluster runs on jnlp image instead of specified one Kubernetes 尝试将 jenkins 添加到集群 - Kubernetes Try to add jenkins to a cluster Jenkins - Puge 构建历史日志 - 配置一个作业以仅保留最近 100 个构建历史并删除其余的 - Jenkins - Puge build history logs - Configure a job to keep just the last 100 builds history and delete the rest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM