Search code examples
prometheuskube-state-metrics

How to install and configure kube-state-metrics for external prometheus serverto monitor kubernetes


How to install and configure kube-state-metrics to monitor kubernetes on external/separate/centralized prometheus server.

I came across some articles that pointed me to kube-state-metrics but am not sure where i need to run the kube-state-metrics

I have 2 kubernetes cluster and i want to monitor both the kubernetes cluster metrics on Prometheus and grafana(for visualization. How can this be achieve using one prometheus server.


Solution

  • kube-state-metrics is a simple service that listens to the Kubernetes API server and generates metrics about the state of the objects.

    Here you will find a list of yamls: link

    It contains:

    1. Deployment: Where container fetches image: quay.io/coreos/kube-state-metrics:v1.6.0

    2. Service account: Service account of deployment object

    3. Role and RoleBinding: RBAC cluster role and role binding for the service account

    4. Service: k8s service that listen to the pods under deployments

    So when you have all these set up. You are ready to go. Now you configure your prometheus to scrape metrics from the k8s Service you created in no. 4.

    Here you will find how to generate address for the k8s service.

    Configure prometheus:

    global:
      scrape_interval:     15s
      evaluation_interval: 15s
    
    scrape_configs:
      - job_name: 'kube-state-metrics'
        static_configs:
          - targets: ['address'] //address of the k8s service