zoukankan      html  css  js  c++  java
  • Prometheus Operator配置k8s服务自动发现 wang

    # 1.编写prometheus-additional并在monitoring名称空间创建secret资源
    cat > prometheus-additional.yaml << EOF
    - job_name: 'kubernetes-service-endpoints'
      kubernetes_sd_configs:
      - role: endpoints
      relabel_configs:
      - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
        action: keep
        regex: true
      - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
        action: replace
        target_label: __scheme__
        regex: (https?)
      - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
        action: replace
        target_label: __metrics_path__
        regex: (.+)
      - source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
        action: replace
        target_label: __address__
        regex: ([^:]+)(?::\d+)?;(\d+)
        replacement: $1:$2
      - 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: kubernetes_name
    EOF
     
    kubectl create secret generic additional-configs --from-file=prometheus-additional.yaml -n monitoring
     
    # 2.手动修改kube-prometheus/manifests中的prometheus-prometheus.yaml文件增加additionalScrapeConfigs配置段
    vim kube-prometheus/manifests/prometheus-prometheus.yaml
     
      additionalScrapeConfigs:
        name: additional-configs
        key: prometheus-additional.yaml
         
    # 并重新应用prometheus-prometheus.yaml文件
    kubectl apply -f kube-prometheus/manifests/prometheus-prometheus.yaml
    
    # 3.增加授权。运行Prometheus的ServiceAccount名为prometheus-k8s绑定了名为prometheus-k8s的ClusterRole。
    vim prometheus-clusterRole.yaml
    
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: prometheus-k8s
    rules:
    - apiGroups:
      - ""
      resources:
      - nodes
      - services
      - endpoints
      - pods
      - nodes/proxy
      verbs:
      - get
      - list
      - watch
    - apiGroups:
      - ""
      resources:
      - configmaps
      - nodes/metrics
      verbs:
      - get
    - nonResourceURLs:
      - /metrics
      verbs:
      - get
    
    kubectl apply -f prometheus-clusterRole.yaml
    
    # 4.验证。在需要监控的服务service增加annotations字段以实现自动发现。
    kubectl edit service grafana -n monitoring
    
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "3000"
  • 相关阅读:
    Remoting系列(一)Remoting的基本概念
    软件设计师
    如果让我重做一次研究生
    VS2005Web控件拖动
    JS实现文本框回车提交
    SqlDataReader
    SqlCommand.ExecuteScalar
    DataSet
    电子商务部应该做些什么?【转】
    e
  • 原文地址:https://www.cnblogs.com/wang-hongwei/p/15697789.html
Copyright © 2011-2022 走看看