Prometheus kube_pod_container_status_waiting_reason 未捕获 pod CrashLoopBackOff 原因

Posted

技术标签:

【中文标题】Prometheus kube_pod_container_status_waiting_reason 未捕获 pod CrashLoopBackOff 原因【英文标题】:Prometheus kube_pod_container_status_waiting_reason not capturing pod CrashLoopBackOff reason 【发布时间】:2019-05-18 08:52:27 【问题描述】:

根据定义,kube_pod_container_status_waiting_reason 应该捕获 Pod 处于 Waiting 状态的原因。

我的 kubernetes 集群中有几个 Pod 位于 CrashLoopBackOff 中,但我没有看到 kube_pod_container_status_waiting_reason 捕获的原因。 它只捕获了两个原因 - ErrImagePull 和 ContainerCreating。

~$ k get pods -o wide --show-all --all-namespaces | grep Crash
cattle-system   cattle-cluster-agent-6f744c67cc-jlkjh       0/1       CrashLoopBackOff   2885       10d       10.233.121.247   k8s-4
cattle-system   cattle-node-agent-6klkh                     0/1       CrashLoopBackOff   2886       171d      10.171.201.127   k8s-2
cattle-system   cattle-node-agent-j6r94                     0/1       CrashLoopBackOff   2887       171d      10.171.201.110   k8s-3
cattle-system   cattle-node-agent-nkfcq                     0/1       CrashLoopBackOff   17775      171d      10.171.201.131   k8s-1
cattle-system   cattle-node-agent-np76b                     0/1       CrashLoopBackOff   2887       171d      10.171.201.89    k8s-4
cattle-system   cattle-node-agent-pwn5v                     0/1       CrashLoopBackOff   2859       171d      10.171.202.72    k8s-5

在 prometheus 中运行 sum by (reason) (kube_pod_container_status_waiting_reason) 会产生结果:

Element                       Value
reason="ContainerCreating"    0
reason="ErrImagePull"         0

我正在运行quay.io/coreos/kube-state-metrics:v1.2.0 kube-state-metrics 的图像。

我错过了什么?为什么 CrashLoopBackOff 原因没有出现在查询中? 我想设置一个警报,查找处于等待状态的 pod 并说明原因。所以想合并kube_pod_container_status_waiting查找处于等待状态的pods和kube_pod_container_status_waiting_reason查找确切原因。

请帮忙。谢谢!

【问题讨论】:

【参考方案1】:

您遇到了this。基本上,看起来您正在使用 kube-state-metrics 1.2.0 或更早版本。您会看到ImagePullBackOffCrashLoopBackOff 被添加到1.3.0 中。

所以更新你的图片:

k8s.gcr.io/kube-state-metrics:v1.3.0
quay.io/coreos/kube-state-metrics:v1.3.0

k8s.gcr.io/kube-state-metrics:v1.4.0
quay.io/coreos/kube-state-metrics:v1.4.0

【讨论】:

以上是关于Prometheus kube_pod_container_status_waiting_reason 未捕获 pod CrashLoopBackOff 原因的主要内容,如果未能解决你的问题,请参考以下文章

prometheus视频教程

grafana和prometheus系列六:prometheus默认存储

2019最新 prometheus视频教程 prometheus监控视频 prometheus入门与实践教程

2019最新 prometheus视频教程 prometheus监控视频 prometheus入门与实践教程

Prometheus简介

Prometheus学习系列之Prometheus 联盟迁移