> ## Content Index
> Fetch the complete content index at: https://devopscube.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How To Setup Kube State Metrics on Kubernetes
- URL: https://devopscube.com/setup-kube-state-metrics/
- Published: 2022-01-27T05:12:00.000Z
- Updated: 2025-03-15T05:21:48.000Z
- Author: Bibin Wilson
- Tags: Kubernetes, MONITORING, #Migrated-1741795015845, #wp, #wp-post, #Import 2025-03-12 15:57, #blog

In this blog, we will look at what is Kube State Metrics and its setup on Kubernetes. This blog is part of the [Prometheus kubernetes setup tutorial](https://devopscube.com/setup-prometheus-monitoring-on-kubernetes/) series.

## What is Kube State Metrics?

[Kube State metrics](https://github.com/kubernetes/kube-state-metrics?ref=devopscube.com) is a service that talks to the Kubernetes API server to get all the details about all the API objects like deployments, pods, daemonsets, Statefulsets, etc.

Primarily it produces metrics in Prometheus format with the stability as the Kubernetes API. Overall it provides kubernetes objects & resources metrics that you cannot get directly from native Kubernetes monitoring components.

Kube state metrics service exposes all the metrics on `/metrics` URI. [Prometheus](https://devopscube.com/setup-prometheus-monitoring-on-kubernetes/) can scrape all the metrics exposed by Kube state metrics.

Following are some of the important metrics you can get from Kube state metrics.

1. Node status, node capacity (CPU and memory)
2. Replica-set compliance (desired/available/unavailable/updated status of replicas per deployment)
3. Pod status (waiting, running, ready, etc)
4. Ingress metrics
5. PV, PVC metrics
6. Daemonset & Statefulset metrics.
7. Resource requests and limits.
8. Job & Cronjob metrics

You can check out the detailed supported metrics from the [documentation here](https://github.com/kubernetes/kube-state-metrics/tree/master/docs?ref=devopscube.com).

## Kube State Metrics Setup

Kube state metrics is available as a public docker image. You will have to deploy the following Kubernetes objects for Kube state metrics to work.

1. A **Service Account**
2. **Cluster Role** \- For kube state metrics to access all the Kubernetes API objects.
3. **Cluster Role Binding** \- Binds the service account with the cluster role.
4. Kube State Metrics **Deployment**
5. **Service** \- To expose the metrics

All the above Kube state metrics objects will be deployed in the `kube-system` namespace

Let's deploy the components. All the deployment objects are available in Github. You can also find the same deployment object in the [official repo](https://github.com/kubernetes/kube-state-metrics/tree/master/examples/standard?ref=devopscube.com) as well.

**Step 1:** Clone the Github repo

```
git clone https://github.com/devopscube/kube-state-metrics-configs.git
```

**Step 2:** Create all the objects by pointing to the cloned directory.

```
kubectl apply -f kube-state-metrics-configs/
```

**Step 3:** Check the deployment status using the following command.

```
kubectl get deployments kube-state-metrics -n kube-system
```

## kube State Metrics Prometheus Config

All the Kube static metrics can be obtained from the Kube state service endpoint on `/metrics` URI.

This configuration can be added as part of the **Prometheus job configuration**. You need to add the following job configuration to your Prometheus config for Prometheus to scrape all the Kube state metrics.

💡

****Note**: If you have followed my prometheus guide, you dont have to add this scrape config. It is already part of the [prometheus config](https://github.com/bibinwilson/kubernetes-prometheus/blob/master/config-map.yaml?ref=devopscube.com). You should see the target status "up" after deploying kube state metrics.

If you have follo

```
- job_name: 'kube-state-metrics'
  static_configs:
    - targets: ['kube-state-metrics.kube-system.svc.cluster.local:8080']

```