本文永久链接: https://www.xtplayer.cn/prometheus/missing-kube-node-labels-in-prometheus/

从 kube-state-metrics 2.0.0 开始,默认不再自动导出所有资源的标签数据,比如 pod 标签和 node 标签。

如果要搜集相关资源的标签数据,可以在 rancher ui 编辑 kube-state-metrics deployment,在命令中添加 --metric-labels-allowlist=nodes=[*],pods=[*] ,多个资源以逗号隔开。或者在集群工具中编辑 Monitoring App 的 YAML,在 kube-state-metrics 层级下添加 metricLabelsAllowlist ,配置示例如下:

kube-state-metrics:
metricLabelsAllowlist:
- nodes=[*]
- pods=[*]
namespaceOverride: ''
prometheus:
monitor:
enabled: true
honorLabels: true
interval: ''
labelLimit: 0
labelNameLengthLimit: 0
labelValueLengthLimit: 0

对于非生产环境,可以将参数写成 '*=[*]',表示导出所有资源的标签。比如按以下方式配置

--metric-labels-allowlist=*=[*]

或者

kube-state-metrics:
metricLabelsAllowlist:
- '*=[*]'

但是这种方式会导出所有资源标签,对 Prometheus 会存在一定负担。因此建议通过指定资源的方式导出标签,可用资源通常包含以下类型:

resources=certificatesigningrequests,configmaps,cronjobs,daemonsets,deployments,endpoints,horizontalpodautoscalers,ingresses,jobs,leases,limitranges,mutatingwebhookconfigurations,namespaces,networkpolicies,nodes,persistentvolumeclaims,persistentvolumes,poddisruptionbudgets,pods,replicasets,replicationcontrollers,resourcequotas,secrets,services,statefulsets,storageclasses,validatingwebhookconfigurations,volumeattachments

参考 issue:

https://github.com/kubernetes/kube-state-metrics/issues/1270#issuecomment-712986441

https://github.com/kubernetes/kube-state-metrics/issues/1968#issuecomment-1422592377