talira

kube-state-metrics

Add-on agent to generate and expose cluster-level metrics about the state of Kubernetes objects

open sourceApache-2.0self-hostablefree

kube-state-metrics (KSM) listens to the Kubernetes API server and generates metrics about the state of objects such as deployments, nodes and pods, served in Prometheus text format on /metrics for Prometheus or any compatible scraper. It exposes the API's raw data unmodified, so its numbers can differ from kubectl's, and it holds a snapshot of cluster state in memory rather than storing history. Large clusters can be split across instances by sharding. It is a Kubernetes project sponsored by SIG Instrumentation, Apache-2.0, and its official Helm chart is maintained in the prometheus-community charts repository.

Ways to install

Problems it solves

  • alert when a deployment has fewer ready replicas than it should
  • count pods stuck in Pending or CrashLoopBackOff across the whole cluster in Prometheus
  • graph how many pods restart per namespace over time
  • know when a Kubernetes CronJob or Job failed from my monitoring system
  • expose node conditions like DiskPressure or NotReady as metrics
  • track resource requests and limits per container to plan cluster capacity
  • turn Kubernetes object labels into Prometheus labels so I can group metrics by team
  • alert when a PersistentVolumeClaim stays unbound
  • generate metrics from the status fields of my own custom resources
  • monitor the state of thousands of objects in a big cluster without one huge exporter process

Features

  • metrics for the state of Kubernetes objects such as deployments, nodes, pods and jobs
  • Prometheus text format on /metrics (port 8080 by default)
  • raw values from the Kubernetes API, unmodified
  • custom resource state metrics from your own CRDs (feature-frozen)
  • Kubernetes labels exposed as Prometheus labels, with conflict resolution
  • allow and deny lists for metrics
  • horizontal sharding, automated in a StatefulSet, and DaemonSet sharding for pod metrics
  • namespace and resource filtering for limited-privilege deployments
  • healthz, livez and readyz endpoints
  • multi-architecture images: amd64, arm, arm64, ppc64le and s390x

Limitations

  • Doesn't store or forward metrics: it serves the cluster's current object state on /metrics for Prometheus or another scraper to collect1