7.3. 解决 Prometheus 的 KubePersistentVolumeFillingUp 警报触发的问题
作为集群管理员,您可以解析 Prometheus 触发的 KubePersistentVolumeFillingUp
警报。
当 openshift-monitoring
项目中的 prometheus-k8s-*
pod 声明的持久性卷 (PV) 时,关键警报会在剩余的总空间少于 3% 时触发。这可能导致 Prometheus 正常正常工作。
注意
有两个 KubePersistentVolumeFillingUp
警报:
-
Critical 警报 :当挂载的 PV 小于 3% 的总空间时,会触发具有
severity="critical"
标签的警报。 -
Warning 警报 :当挂载的 PV 的总空间低于 15% 时,会触发带有
severity="warning"
标签的警报,且预期在四天内填满。
要解决这个问题,您可以删除 Prometheus 时间序列数据库 (TSDB) 块来为 PV 创建更多空间。
先决条件
-
您可以使用具有
cluster-admin
集群角色的用户身份访问集群。 -
已安装 OpenShift CLI(
oc
)。
流程
运行以下命令,列出所有 TSDB 块的大小,从最旧的到最新排序:
oc debug <prometheus_k8s_pod_name> -n openshift-monitoring \ -c prometheus --image=$(oc get po -n openshift-monitoring <prometheus_k8s_pod_name> \ -o jsonpath='{.spec.containers[?(@.name=="prometheus")].image}') \ -- sh -c 'cd /prometheus/;du -hs $(ls -dtr */ | grep -Eo "[0-9|A-Z]{26}")'
$ oc debug <prometheus_k8s_pod_name> -n openshift-monitoring \
1 -c prometheus --image=$(oc get po -n openshift-monitoring <prometheus_k8s_pod_name> \
2 -o jsonpath='{.spec.containers[?(@.name=="prometheus")].image}') \ -- sh -c 'cd /prometheus/;du -hs $(ls -dtr */ | grep -Eo "[0-9|A-Z]{26}")'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 确定可以删除哪些块以及多少块,然后删除块。以下示例命令从
prometheus-k8s-0
pod 中删除三个最旧的 Prometheus TSDB 块:oc debug prometheus-k8s-0 -n openshift-monitoring \ -c prometheus --image=$(oc get po -n openshift-monitoring prometheus-k8s-0 \ -o jsonpath='{.spec.containers[?(@.name=="prometheus")].image}') \ -- sh -c 'ls -latr /prometheus/ | egrep -o "[0-9|A-Z]{26}" | head -3 | \ while read BLOCK; do rm -r /prometheus/$BLOCK; done'
$ oc debug prometheus-k8s-0 -n openshift-monitoring \ -c prometheus --image=$(oc get po -n openshift-monitoring prometheus-k8s-0 \ -o jsonpath='{.spec.containers[?(@.name=="prometheus")].image}') \ -- sh -c 'ls -latr /prometheus/ | egrep -o "[0-9|A-Z]{26}" | head -3 | \ while read BLOCK; do rm -r /prometheus/$BLOCK; done'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 运行以下命令,验证挂载的 PV 的使用并确保有足够的可用空间:
oc debug <prometheus_k8s_pod_name> -n openshift-monitoring \ --image=$(oc get po -n openshift-monitoring <prometheus_k8s_pod_name> \ -o jsonpath='{.spec.containers[?(@.name=="prometheus")].image}') -- df -h /prometheus/
$ oc debug <prometheus_k8s_pod_name> -n openshift-monitoring \
1 --image=$(oc get po -n openshift-monitoring <prometheus_k8s_pod_name> \
2 -o jsonpath='{.spec.containers[?(@.name=="prometheus")].image}') -- df -h /prometheus/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 以下示例显示了由
prometheus-k8s-0
pod 声明的挂载的 PV,该 pod 剩余 63%:输出示例
Starting pod/prometheus-k8s-0-debug-j82w4 ... Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p4 40G 15G 40G 37% /prometheus Removing debug pod ...
Starting pod/prometheus-k8s-0-debug-j82w4 ... Filesystem Size Used Avail Use% Mounted on /dev/nvme0n1p4 40G 15G 40G 37% /prometheus Removing debug pod ...
Copy to Clipboard Copied! Toggle word wrap Toggle overflow