首页 > 其他分享 >15.6 创建prometheus使用的配置configmap

15.6 创建prometheus使用的配置configmap

时间:2024-09-24 14:25:45浏览次数:9  
标签:__ configmap 15.6 kubernetes prometheus meta io action name


本节重点介绍 :

  • config简介
  • prometheus configmap编写

configmap

作用

  • ConfigMap 是一种 API 对象,用来将非机密性的数据保存到键值对中
  • 使用时, Pods 可以将其用作环境变量、命令行参数或者存储卷中的配置文件。

为何prometheus需要configmap

  • prometheus的配置文件需要以configmap形式挂载

编写prometheus 的configmap

  • 字段中具体含义再后面的章节中再一一解释
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-config
  namespace: kube-system
data:
  prometheus.yml: |
    global:
      scrape_interval:     30s
      evaluation_interval: 30s
      external_labels:
        cluster: "01"
    scrape_configs:
    - job_name: kube-etcd
      kubernetes_sd_configs:
      - role: endpoints
      scheme: https
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name]
        action: keep
        regex: kube-system;kube-etcd
      tls_config:
        ca_file: /etc/prometheus/secrets/etcd-certs/ca.crt
        cert_file: /etc/prometheus/secrets/etcd-certs/healthcheck-client.crt
        key_file: /etc/prometheus/secrets/etcd-certs/healthcheck-client.key
        insecure_skip_verify: true
    - job_name: 'kube-scheduler'
      kubernetes_sd_configs:
      - role: endpoints
      scheme: https
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name]
        action: keep
        regex: kube-system;kube-scheduler
    - job_name: 'kube-controller-manager'
      kubernetes_sd_configs:
      - role: endpoints
      scheme: https
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name]
        action: keep
        regex: kube-system;kube-controller-manager
    - job_name: 'kubernetes-apiservers'
      kubernetes_sd_configs:
      - role: endpoints
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
        action: keep
        regex: default;kubernetes;https
    - job_name: kube-state-metrics
      metrics_path: /metrics
      scheme: http
      static_configs:
      - targets:
        - kube-state-metrics:8080

    - job_name: kubernetes-nodes-kubelet
      kubernetes_sd_configs:
      - role: node
      relabel_configs:
      - action: labelmap
        regex: __meta_kubernetes_node_label_(.+)
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    - job_name: kubernetes-nodes-cadvisor
      metrics_path: /metrics
      scheme: https
      kubernetes_sd_configs:
      - role: node
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      relabel_configs:
      - action: replace
        regex: (.+)
        source_labels:
        - __meta_kubernetes_node_label_kubernetes_io_hostname
        target_label: node
      - separator: ;
        regex: __meta_kubernetes_node_label_(.+)
        replacement: $1
        action: labelmap
      - separator: ;
        regex: (.*)
        target_label: __metrics_path__
        replacement: /metrics/cadvisor
        action: replace
    - job_name: kubernetes-pods
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      kubernetes_sd_configs:
      - role: pod
      relabel_configs:
      - action: keep
        regex: true
        source_labels:
        - __meta_kubernetes_pod_annotation_prometheus_io_scrape
      - action: replace
        regex: (.+)
        source_labels:
        - __meta_kubernetes_pod_annotation_prometheus_io_path
        target_label: __metrics_path__
      - action: replace
        regex: ([^:]+)(?::\d+)?;(\d+)
        replacement: $1:$2
        source_labels:
        - __address__
        - __meta_kubernetes_pod_annotation_prometheus_io_port
        target_label: __address__
      - action: labelmap
        regex: __meta_kubernetes_pod_label_(.+)
      - action: replace
        source_labels:
        - __meta_kubernetes_namespace
        target_label: kubernetes_namespace
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_name
        target_label: kubernetes_pod_name
    - 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
      - source_labels: [__address__]
        action: replace
        target_label: instance
        regex: (.+):(.+)
        replacement: $1

本节重点介绍 :

  • config简介
  • prometheus configmap编写


标签:__,configmap,15.6,kubernetes,prometheus,meta,io,action,name
From: https://blog.51cto.com/moonfdd/12099430

相关文章

  • prometheus学习笔记之PushGateway
    一、pushgateway简介pushgateway是采用被动推送的方式,而不是类似于prometheusserver主动连接exporter获取监控数据。pushgateway可以单独运行在一个节点,然后需要自定义监控脚本把需要监控的主动推送给pushgateway的API接口,然后pushgateway再等待prometheusser......
  • Python实战:为Prometheus开发自定义Exporter
    Python实战:为Prometheus开发自定义Exporter在当今的微服务架构和容器化部署环境中,监控系统的重要性不言而喻。Prometheus作为一款开源的系统监控和警报工具,以其强大的功能和灵活性受到了广泛的欢迎。然而,Prometheus本身并不直接监控所有类型的服务或应用,这就需要我们为其开发自定......
  • 搭建基于Grafana+Prometheus+Nvidia_gpu_exploter的GPU监控平台
    搭建基于Grafana+Prometheus+Nvidia_gpu_exploter的英伟达GPU监控平台在现代数据科学和机器学习领域,GPU已成为不可或缺的硬件资源。为了高效管理和监控GPU的使用情况,构建一个实时、直观的监控系统变得尤为重要。本文将详细介绍如何使用Grafana、Prometheus以及Nvidia_gpu_explote......
  • ​​Prometheus监控之服务发现
    1.Prometheus服务发现1.1为什么需要服务发现Prometheus采⽤Pull模型来抓取⽬标主机的指标数据,这就意味着Prometheus必须事先知道每个要监控的⽬标的端点地址。然后才能从对应的Exporter或Instrumentation进⾏数据抓取。对于规模较⼩,且监控的⽬标不会频繁的发⽣变动,直接使⽤但......
  • Prometheus 监控系统
    目录1.Prometheus概述(1)TSDB作为Prometheus的存储引擎完美契合了监控数据的应用场景(2)Prometheus的特点(3)Prometheus的主要组件(1)prometheusserver(2)exporter(3)alertmanager(4)pushgateway(5)grafana(4)Prometheus的局限性2.Zabbix和Prometheus的区别?如何选择?(1)Zabbix(2)Prometheus3.Prome......
  • prometheus学习笔记之alertmanager告警配置
    一、安装alertmanager项目地址:https://github.com/prometheus/alertmanager帮助文档:https://prometheus.io/docs/alerting/latest/alertmanager/配置文档:https://prometheus.io/docs/alerting/latest/configuration/wgethttps://github.com/prometheus/alertmanager/release......
  • 基于Prometheus和Grafana的现代服务器监控体系构建
    引言随着云计算和微服务架构的迅速发展,服务器监控已成为保障系统稳定性和性能的重要手段。Prometheus和Grafana作为两个非常受欢迎的开源项目,为构建现代监控体系提供了强有力的支持。本文将详细探讨如何使用Prometheus和Grafana构建现代服务器监控体系,并结合实际案例进行技术......
  • 云原生周刊:Prometheus 3.0 Beta 发布|2024.09.16
    开源项目推荐KumaKuma是一个现代化的基于Envoy的服务网格,能够在每个云平台上运行,支持单区域或多区域部署,兼容Kubernetes和虚拟机。凭借其广泛的通用工作负载支持,以及对Envoy数据平面代理技术的原生支持(但无需Envoy专业知识),Kuma提供了现代化的L4-L7服务连接、发现、......
  • Prometheus修改数据存储位置
    Prometheus修改数据存储位置Prometheus的数据存储位置可以通过配置文件中的--storage.tsdb.path参数来指定。默认情况下,数据存储在Prometheus安装目录下的data文件夹中。要修改数据存储位置,可以在Prometheus启动命令中添加或修改该参数。步骤1:修改Prometheus启动命令接......
  • ​​Prometheus监控之postgresql
    1 postgres_exporterpostgres_exporter是一个开源的监控工具,专门设计用于收集和导出PostgreSQL数据库的性能指标,以便进行监控和分析。它是Prometheus监控框架的一部分,可以将收集到的数据格式化为Prometheus可以识别的格式。1.1 安装配置postgres_exporter1.1.1下载postgres_expo......