kubesphere/kube-state-metrics原生kube-state-metrics作为Kubernetes集群资源状态指标的核心采集工具,在企业级运维中存在一些实际痛点:指标覆盖不够全面(如缺乏自定义资源、存储/网络深度指标)、配置灵活性低(自定义指标需修改源码或复杂配置)、高负载场景下资源占用偏高。KubeSphere基于大量用户反馈,对其进行针对性改造,旨在提升监控能力、简化使用流程,同时保障性能稳定性。
deployment_rollout_progress)、StatefulSet序号就绪状态(statefulset_ordinal_ready)等,解决原生版本中“只看副本数,不知更新是否卡住”的问题。persistentvolumeclaim_usage_bytes)、Service后端Endpoint健康比例(service_endpoint_healthy_ratio),覆盖存储资源耗尽预警、服务流量分发监控等场景。ClusterResourceQuota、用户业务CRD),满足业务自定义监控需求。metrics-rules.yaml定义需采集的资源类型、字段路径及指标名称,支持标签过滤(如仅采集prod命名空间资源)。例如:
yaml# 采集Namespace标签为env=prod的Deployment可用副本数 workloads: - resource: deployments namespaces: matchLabels: env=prod metrics: - name: deployment_available_replicas field: status.availableReplicas type: Gauge
ConfigMap中的metrics-rules.yaml配置指标规则,执行:
bashkubectl apply -f deploy/
以采集业务CRD MyApp(group: example.com, version: v1)的status.readyReplicas为例:
metrics-rules.yaml中添加规则:
yamlcustomResources: - name: myapps group: example.com version: v1 metrics: - name: myapp_ready_replicas help: "Number of ready replicas in MyApp" field: status.readyReplicas type: Gauge labels: # 提取资源标签作为指标标签 - key: app valueFrom: metadata.labels.app
bashkubectl rollout restart deployment kube-state-metrics -n kube-system
bashkubectl exec -it <pod-name> -n kube-system -- curl localhost:8080/metrics | grep myapp_ready_replicas
8080端口,直接在Prometheus的ServiceMonitor中添加如下配置即可采集:
yamlapiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: kube-state-metrics spec: selector: matchLabels: app.kubernetes.io/name: kube-state-metrics endpoints: - port: http-metrics
Order、Payment),需采集其状态指标用于业务告警。apiextensions.k8s.io/v1(避免使用旧版v1beta1)。kubectl get <crd-name> <instance> -o yaml确认字段存在(如status.readyReplicas是否真实存在于CRD中)。--kube-api-qps=200 --kube-api-burst=400(默认100/200),避免API限流。通过上述优化,KubeSphere版kube-state-metrics在保留原生工具核心能力的基础上,更贴合企业实际监控需求,降低了自定义指标门槛,同时保障了大规模集群下的性能稳定。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务