kube-state-metrics is a service that watches the Kubernetes API and exposes metrics about the state of objects in your cluster (e.g. pod status, node capacity, deployment replicas, resource requests and limits). It does not report resource usage (CPU/memory usage); that is provided by the Kubernetes metrics server and is used for scaling (e.g. HPA). kube-state-metrics focuses on object state (e.g. desired vs. available replicas, pod phase, node conditions), which is useful for alerting and dashboards in Prometheus and Grafana.
In this guide you will:
- Understand what kube-state-metrics provides and how it fits with Prometheus
- Install kube-state-metrics using manifests (ServiceAccount, ClusterRole, ClusterRoleBinding, Deployment, Service) or Helm
- Optionally tune resources and limit exposed metrics
- Add a Prometheus scrape job so Prometheus can collect the metrics
Prerequisites: A Kubernetes cluster (1.20+) with kubectl configured. For Prometheus integration, Prometheus must be installed (e.g. How to Setup Prometheus Monitoring on Kubernetes).
What kube-state-metrics Provides
kube-state-metrics exposes metrics on an HTTP endpoint in Prometheus exposition format. Prometheus scrapes this endpoint and stores the metrics; you can then query them with PromQL and visualize them in Grafana.
Examples of metrics (see official docs for the full list):
- Nodes: status, capacity (CPU, memory), allocatable
- Pods: status (waiting, running, ready), phase, restarts
- Deployments / ReplicaSets: desired, available, unavailable, updated replicas
- StatefulSets / DaemonSets: similar replica and status metrics
- Jobs / CronJobs: active, failed, succeeded, completion time
- Ingress: info, backend metrics
- PersistentVolumes / PersistentVolumeClaims: status, capacity, phase
- Resource requests and limits (from pod specs)
- HorizontalPodAutoscalers, PodDisruptionBudgets, and other API objects
Benefits:
- Metrics at an HTTP endpoint (e.g.
http://kube-state-metrics:8080/metrics) - Prometheus exposition format, so Prometheus can scrape without extra conversion
- Raw data derived from the Kubernetes API (list/watch)
You can open the /metrics URL in a browser, but the output is plain text; Prometheus and Grafana make it queryable and visual.
Installing with Manifests
You can deploy kube-state-metrics by applying Kubernetes manifests. All resources below go in the kube-system namespace. You need: ServiceAccount, ClusterRole, ClusterRoleBinding, Deployment, and Service.
1. Service Account
service-account.yaml:
| |
| |
2. ClusterRole
cluster-role.yaml: (grants list/watch on the API resources kube-state-metrics needs)
| |
| |
3. ClusterRoleBinding
cluster-role-binding.yaml:
| |
| |
4. Deployment
deployment.yaml:
| |
| |
5. Service
service.yaml:
| |
| |
Installing with Helm
You can install kube-state-metrics using the prometheus-community Helm chart.
| |
To override settings (e.g. resources, replicas, metric allowlist), create a values.yaml and pass it to helm install or helm upgrade:
| |
The chart installs the Deployment and Service in the namespace you specify (e.g. kube-system). Replace values.yaml with the path to your overrides file.
Verifying the Installation
Check that the pod is running:
1kubectl get pods -n kube-system -l app.kubernetes.io/name=kube-state-metricsPort-forward and hit the metrics endpoint:
1kubectl port-forward -n kube-system svc/kube-state-metrics 8080:8080In another terminal:
1curl http://127.0.0.1:8080/metricsYou should see Prometheus-format metrics (e.g.
kube_node_info,kube_pod_status_phase).Filter a specific metric (example):
1curl -s http://127.0.0.1:8080/metrics | grep kube_node_status_capacity
Configuring Prometheus to Scrape kube-state-metrics
Add a scrape job to your Prometheus configuration so Prometheus collects these metrics. If kube-state-metrics is in kube-system and the Service name is kube-state-metrics:
| |
Reload or restart Prometheus after changing the config. Then you can query metrics (e.g. in Prometheus UI or Grafana). For a full Prometheus-on-Kubernetes setup, see How to Setup Prometheus Monitoring on Kubernetes.
Scaling and Resource Tuning
As the cluster grows, the /metrics response can become larger and slower. Allocate enough CPU and memory so kube-state-metrics stays responsive.
Suggested starting values: around 250Mi memory and 0.1 cores (100m CPU). Increase as needed. Setting CPU too low can cause high latency or OOMs.
Example override with Helm (e.g. in resources.yaml):
| |
Apply with:
| |
(Remove the trailing . from the chart name if you had it; the correct chart reference is prometheus-community/kube-state-metrics.)
Limiting Exposed Metrics
To reduce cardinality and scrape size, you can expose only a subset of metrics using the chart’s metric allowlist (or the container’s --metric-allowlist if running from manifests).
Example values.yaml for Helm:
| |
Then:
| |
kube-state-metrics will then expose only the metrics in the allowlist. See the chart values and kube-state-metrics docs for options.
Summary
- kube-state-metrics exposes Kubernetes object state metrics (pods, nodes, deployments, etc.) in Prometheus format on an HTTP endpoint. It does not report resource usage; use the metrics server for that.
- Install via manifests (ServiceAccount, ClusterRole, ClusterRoleBinding, Deployment, Service) in
kube-systemor via the Helm chartprometheus-community/kube-state-metrics. - Verify with
kubectl get pods, port-forward, andcurl .../metrics. Add a Prometheus scrape job forkube-state-metrics.kube-system.svc.cluster.local:8080. - Scale by increasing CPU/memory; use metric allowlisting to reduce cardinality.
To build full dashboards and alerts, combine kube-state-metrics with Prometheus and Grafana. For Prometheus on Kubernetes, see How to Setup Prometheus Monitoring on Kubernetes and Monitor Linux Server With Prometheus and Grafana.
Related Posts
- How to Setup Prometheus Monitoring on Kubernetes – Prometheus and scrape configs
- Monitor Linux Server With Prometheus and Grafana – Prometheus + Grafana on a host
- Production-Ready Prometheus on Kubernetes – Prometheus with auth and HA
- How to Set up Prometheus Node Exporter in Kubernetes – Host metrics in the cluster