Environment 环境A Kubernetes cluster provisioned by the RKE2 CLI or Rancher v2.x由 RKE2 CLI 或 Rancher v2.x 配置的 Kubernetes 集群Situation 地理位置By default, kube-state-metrics in Rancher Monitoring exports only a limited set of Kubernetes labels to help optimize resource usage and avoid excessive data collection in Prometheus. If you need additional labels to be included in the metrics for better monitoring or alerting, you can easily customize the values.yaml file of the rancher-monitoring chart to export those labels.默认情况下Rancher Monitoring 中的 kube-state-metrics 只导出有限的 Kubernetes 标签集以帮助优化资源使用避免 Prometheus 中过度收集数据。如果你需要在指标中加入额外标签以更好地监控或提醒可以轻松自定义 Rancher-Monitoring 图表中的 values.yaml 文件来导出这些标签。Resolution 结局Why Customize Labels? 为什么要定制标签Sometimes, you may need more granular insights into your Kubernetes cluster. For example, you might want to track node group labels, application versions, or specific zone information. By exporting additional labels, you can enrich your metrics and enable more precise monitoring, alerting, and troubleshooting.有时您可能需要对 Kubernetes 集群提供更细致的洞察。例如您可能需要跟踪节点组标签、应用版本或特定区域信息。通过导出额外标签您可以丰富指标实现更精准的监控、警报和故障排除。How to Export Additional Labels如何导出额外标签To export additional labels, you can modify the metricLabelsAllowlist setting in the values.yaml file of the rancher-monitoring chart. This configuration lets you specify which labels to include for specific Kubernetes resources like nodes, pods, or namespaces.要导出更多标签可以在 rancher-monitoring 图表的 values.yaml 文件中修改 metricLabelsAllowlist 设置。该配置允许你指定为特定 Kubernetes 资源如节点、播客或命名空间添加哪些标签。Go to Rancher UI ☰ Apps Installed apps rancher-monitoring, click on Edit/Upgrade option and then edit the helm values.进入牧场主 UI ☰应用已安装应用牧场主监控点击编辑/升级选项然后编辑舵手的数值。Example: Include All Labels for Nodes示例包含所有节点标签If you need to include all labels for nodes (which can be useful but should be used cautiously due to performance considerations), you can use the wildcard *:如果你需要包含所有节点标签这很有用但因性能考虑需谨慎使用可以使用通配符 *kube-state-metrics:metricLabelsAllowlist:- nodes[*]Warning: Using * will includealllabels for nodes, which may increase the resource usage in Prometheus.警告使用 * 会包含所有节点标签这可能会增加 Prometheus 中的资源使用。If you want to add specific labels for namespaces and pods, you can configure it like this:如果你想为命名空间和 pod 添加特定标签可以这样配置kube-state-metrics:metricLabelsAllowlist:- namespaces[k8s-label-1, k8s-label-2]- pods[app, version]访问Rancher-K8S解决方案博主企业合作伙伴 https://blog.csdn.net/lidw2009
86. 如何在 Prometheus 的 kube-state-metrics 中加入额外的资源标签
Environment 环境A Kubernetes cluster provisioned by the RKE2 CLI or Rancher v2.x由 RKE2 CLI 或 Rancher v2.x 配置的 Kubernetes 集群Situation 地理位置By default, kube-state-metrics in Rancher Monitoring exports only a limited set of Kubernetes labels to help optimize resource usage and avoid excessive data collection in Prometheus. If you need additional labels to be included in the metrics for better monitoring or alerting, you can easily customize the values.yaml file of the rancher-monitoring chart to export those labels.默认情况下Rancher Monitoring 中的 kube-state-metrics 只导出有限的 Kubernetes 标签集以帮助优化资源使用避免 Prometheus 中过度收集数据。如果你需要在指标中加入额外标签以更好地监控或提醒可以轻松自定义 Rancher-Monitoring 图表中的 values.yaml 文件来导出这些标签。Resolution 结局Why Customize Labels? 为什么要定制标签Sometimes, you may need more granular insights into your Kubernetes cluster. For example, you might want to track node group labels, application versions, or specific zone information. By exporting additional labels, you can enrich your metrics and enable more precise monitoring, alerting, and troubleshooting.有时您可能需要对 Kubernetes 集群提供更细致的洞察。例如您可能需要跟踪节点组标签、应用版本或特定区域信息。通过导出额外标签您可以丰富指标实现更精准的监控、警报和故障排除。How to Export Additional Labels如何导出额外标签To export additional labels, you can modify the metricLabelsAllowlist setting in the values.yaml file of the rancher-monitoring chart. This configuration lets you specify which labels to include for specific Kubernetes resources like nodes, pods, or namespaces.要导出更多标签可以在 rancher-monitoring 图表的 values.yaml 文件中修改 metricLabelsAllowlist 设置。该配置允许你指定为特定 Kubernetes 资源如节点、播客或命名空间添加哪些标签。Go to Rancher UI ☰ Apps Installed apps rancher-monitoring, click on Edit/Upgrade option and then edit the helm values.进入牧场主 UI ☰应用已安装应用牧场主监控点击编辑/升级选项然后编辑舵手的数值。Example: Include All Labels for Nodes示例包含所有节点标签If you need to include all labels for nodes (which can be useful but should be used cautiously due to performance considerations), you can use the wildcard *:如果你需要包含所有节点标签这很有用但因性能考虑需谨慎使用可以使用通配符 *kube-state-metrics:metricLabelsAllowlist:- nodes[*]Warning: Using * will includealllabels for nodes, which may increase the resource usage in Prometheus.警告使用 * 会包含所有节点标签这可能会增加 Prometheus 中的资源使用。If you want to add specific labels for namespaces and pods, you can configure it like this:如果你想为命名空间和 pod 添加特定标签可以这样配置kube-state-metrics:metricLabelsAllowlist:- namespaces[k8s-label-1, k8s-label-2]- pods[app, version]访问Rancher-K8S解决方案博主企业合作伙伴 https://blog.csdn.net/lidw2009