prometheus (nine) collected kube-state-metrics index information

Installation kube-state-metrics

  1. download

    $ cd /opt/k8s/work/
    $ wget -O kube-state-metrics.zip  https://github.com/kubernetes/kube-state-metrics/archive/master.zip
    $ unzip kube-state-metrics.tar.gz
    $ cd kube-state-metrics-master/examples/standard
    $ ls
    cluster-role-binding.yaml  cluster-role.yaml  deployment.yaml  service-account.yaml  service.yaml
    
  2. Modify namespace

    Modified from the default namespace into kube-system monitoring

    $ cd /opt/k8s/work/kube-state-metrics-master/examples/standard
    $ ls | xargs -I {} sed -i "s/namespace: kube-system/namespace: monitoring/g" {}
    
  3. In the following additional annotation service.yaml

    annotations:
      prometheus.io/scraped: "true"
      
    

    server.yml modified file

    cat service.yaml
     apiVersion: v1
     kind: Service
     metadata:
       annotations:
         prometheus.io/scraped: "true"
       labels:
         app.kubernetes.io/name: kube-state-metrics
         app.kubernetes.io/version: 1.9.5
       name: kube-state-metrics
       namespace: monitoring
     spec:
       clusterIP: None
       ports:
       - name: http-metrics
         port: 8080
         targetPort: http-metrics
       - name: telemetry
         port: 8081
         targetPort: telemetry
       selector:
         app.kubernetes.io/name: kube-state-metrics
     
    
  4. Start Service

    $ cd /opt/k8s/work/kube-state-metrics-master/examples/standard
    $ kubectl create -f .
    
    

prometheus collect metrics

  1. prometheus additional configuration, with only crawl prometheus.io/scraped: "true" annotated endpoint

    - job_name: "kubernetes-service-endpoints"
      kubernetes_sd_configs:
      - role: endpoints
      relabel_configs:
      - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scraped]
        action: keep
        regex: true
      - action: labelmap
        regex: __meta_kubernetes_service_label_(.+)
      - source_labels: [__meta_kubernetes_namespace]
        action: replace
        target_label: kubernetes_namespace
      - source_labels: [__meta_kubernetes_service_name]
        action: replace
        target_label: service_name
     
    
  2. After prometheus reload the configuration, see the corresponding target

    kube-state-metrics corresponding to the pod has two ports, the two display target in the prometheus

Placed grafana

  1. Monitoring download state-metrics from the stencil grafana.com 1. Kubernetes the Deployment Statefulset Daemonset metrics , introduced stencil

    FIG effect grafana

Guess you like

Origin www.cnblogs.com/gaofeng-henu/p/12600496.html