【问题标题】:Fluentd capture when a Kubernetes Pod terminates with the 'CrashLoopBackOff'?当 Kubernetes Pod 以“CrashLoopBackOff”终止时,Fluentd 捕获?
【发布时间】:2025-12-11 02:55:01
【问题描述】:

我正在运行一个 pod,它向“terminationMessagePath”写入一条简单的消息,然后该 pod 以“CrashLoopBackOff”退出。我希望能够通过 Kibana 进行调试,而不必登录到每个 Kubernetes 节点。我查询 Kibana 以从属性原因和消息中获取容器最后状态值“CrashLoopBackOff”,但找不到条目。

我可以在 Kibana 中看到 pod 的字段,但我正在寻找的字段(下面以粗体 yaml 格式显示)是空的。

fluentd 需要什么配置才能从 Kubernetes pod 获取日志?或者需要从 Kubernetes 设置配置

$ kubectl 获取 pod_name_1 -o=yaml

terminationMessagePath: /var/log/containers/dt.log
volumeMounts:
- mountPath: /var/log/containers
  name: data
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
  name: default-token-s0w2n
  readOnly: true
dnsPolicy: ClusterFirst
nodeName: dev-master-01
restartPolicy: Always
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
volumes:
- hostPath:
  path: /var/log/containers
  name: data
- name: default-token-s0w2n
secret:
  defaultMode: 420
  secretName: default-token-s0w2n
status:
conditions:
 - lastProbeTime: null
   lastTransitionTime: 2017-07-05T14:45:11Z
   status: "True"
   type: Initialized
 - lastProbeTime: null
   lastTransitionTime: 2017-07-05T17:00:22Z
   message: 'containers with unready status: [dt-termination-demo]'
   reason: ContainersNotReady
   status: "False"
   type: Ready
 - lastProbeTime: null
   lastTransitionTime: 2017-07-05T14:45:11Z
   status: "True"
   type: PodScheduled
   containerStatuses:
 - containerID: 
   docker://9649c26527cf0e1cd3bd67ba9c606c0b78e6b4f08bacf96175627ddc7d250772
   image: debian
   imageID: docker pullable://docker.io/debian@sha256:
            7d067f77d2ae5a23fe6920f8fbc2936c4b0d417e9d01b26372561860750815f0
   lastState:
   terminated:
   containerID: docker://
   9649c26527cf0e1cd3bd67ba9c606c0b78e6b4f08bacf96175627ddc7d250772              
   exitCode: 0
   finishedAt: 2017-07-05T17:00:22Z
   **message: |
    Sleep expired**
    reason: Completed
   startedAt: 2017-07-05T17:00:12Z
   name: dt-termination-demo
   ready: false
   restartCount: 30
   state:
     waiting:
     message: Back-off 5m0s restarting failed container=dt-termination-demo 
              pod=dt-termination-demo-2814930607-8kshj_
              default(8c247b15-6190-11e7-acb7-00505691210d)
     **reason: CrashLoopBackOff**
   hostIP: 192.21.19.128
   phase: Running
   podIP: 10.0.0.8
   startTime: 2017-07-05T14:45:11Z

【问题讨论】:

    标签: debugging logging kubernetes kibana fluentd


    【解决方案1】:

    当 Fluentd 部署为 DaemonSet 时,它旨在收集来自 Node 和 Pod 的所有日志。作为完成此操作的指南,请检查以下 Yaml 文件和相关的更多存储库:

    如果您需要更多帮助,也可以加入我们的 Slack 频道:

    【讨论】:

    • edsiper,感谢您的回复。 Fluentd 确实从 Node 和 Pod 收集日志,但是当 pod 终止或崩溃并出现“CrashLoopBackOff”错误时它不会收集。在 Kibana 中,我可以通过“CrashLoopBackOff”查看有关 pod 的信息,但在日志或消息中看不到实际的“CrashLoopBackOff”值。日志通常包含容器状态的最后状态和当前状态。带有容器状态信息的命令(kubectl get pod pod_name -o=yaml)