• K8S中的proms配置


    Prometheus支持的多种服务发现机制

    • static_configs: 静态服务发现
    • file_sd_configs: 文件服务发现
    • dns_sd_configs: DNS 服务发现
    • kubernetes_sd_configs: Kubernetes 服务发现
    • consul_sd_configs: Consul 服务发现

    安装参考

    安装方法 请参阅我的两外博文: Prometheus 监控Kubernetes_叱咤少帅(少帅)的博客-CSDN博客_prometheus监控kubernetes

    常规配置

    Kube-prometheus 项目中对其他资源对象的管理是通过 Prometheus-Operator 项目实例来实现的;所以在管理和更新 Prometheus 服务是需要通过 Operator 来实现。
    我们在使用 Kube-prometheus 项目配置 Prometheus 监控后,难免会进行一些调整,增加一些自定义的配置,这时候我们就需要更深入了解 Kube-prometheus 项目是如何配置 Prometheus 服务,并给我们预设什么样的调整配置方式。

    1. ### 配置文件在 secret 中
    2. kubectl get secret -n monitoring
    3. ## 查询endpoint
    4. kubectl get ep -n monitoring

    prometheus-operator 文档参考

    1. ###
    2. https://www.qikqiak.com/post/prometheus-operator-monitor-etcd/
    3. ## 工作原理参考
    4. https://www.cnblogs.com/precipitation/p/15980967.html
    5. ##
    6. https://www.cnblogs.com/wang-hongwei/p/15694644.html
    7. ##
    8. https://help.aliyun.com/document_detail/123394.html

    prometheus-operator 结合consul

    在monitoring名称空间部署consul服务

    为了监控Kafka,Mysql等等explorer客户端,我们结合consul去实现。vim consul.yaml

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: consul
    5. namespace: monitoring
    6. labels:
    7. app: consul
    8. spec:
    9. selector:
    10. matchLabels:
    11. app: consul
    12. replicas: 1
    13. template:
    14. metadata:
    15. name: consul
    16. labels:
    17. app: consul
    18. spec:
    19. containers:
    20. - name: consul
    21. image: consul:1.6.1
    22. ports:
    23. - containerPort: 8500
    24. protocol: TCP
    25. imagePullPolicy: IfNotPresent
    26. ---
    27. apiVersion: v1
    28. kind: Service
    29. metadata:
    30. name: consul
    31. namespace: monitoring
    32. labels:
    33. app: consul
    34. spec:
    35. type: NodePort
    36. selector:
    37. app: consul
    38. ports:
    39. - name: consul
    40. protocol: TCP
    41. port: 8500
    42. targetPort: 8500
    43. nodePort: 30300

    编写prometheus-additional并在monitoring名称空间创建secret资源

    vim prometheus-additional.yaml

    1. - job_name: consul
    2. consul_sd_configs:
    3. - server: consul.monitoring.svc:8500
    4. relabel_configs:
    5. - source_labels: [__meta_consul_tags]
    6. regex: .*,prome,.*
    7. action: keep
    8. - source_labels: [__meta_consul_service]
    9. target_label: job

    如果是虚拟机的consul:

    1. - job_name: 'consul-node'
    2. consul_sd_configs:
    3. - server: '192.168.10.13:8500'
    4. datacenter: 'dc1'
    5. scheme: http
    6. services: ['node-exporter']
    7. relabel_configs:
    8. - regex: __meta_consul_service_metadata_(.+)
    9. action: labelmap
    10. - source_labels: ["__meta_consul_service_id"]
    11. target_label: "id"

    写入:

    1. ##
    2. kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --dry-run=client -oyaml > additional-scrape-configs.yaml
    3. ##
    4. kubectl apply -f additional-scrape-configs.yaml -n monitoring
    5. ##
    6. kubectl get secret -n monitoring |grep additional

    手动修改prometheus-prometheus.yaml

    手动修改kube-prometheus/manifests中的prometheus-prometheus.yaml文件增加additionalScrapeConfigs配置段

    vim kube-prometheus/manifests/prometheus-prometheus.yaml

    1. apiVersion: monitoring.coreos.com/v1
    2. kind: Prometheus
    3. metadata:
    4. labels:
    5. app.kubernetes.io/component: prometheus
    6. app.kubernetes.io/instance: k8s
    7. app.kubernetes.io/name: prometheus
    8. app.kubernetes.io/part-of: kube-prometheus
    9. app.kubernetes.io/version: 2.36.1
    10. name: k8s
    11. namespace: monitoring
    12. spec:
    13. alerting:
    14. alertmanagers:
    15. - apiVersion: v2
    16. name: alertmanager-main
    17. namespace: monitoring
    18. port: web
    19. enableFeatures: []
    20. externalLabels: {}
    21. image: quay.io/prometheus/prometheus:v2.36.1
    22. nodeSelector:
    23. kubernetes.io/os: linux
    24. podMetadata:
    25. labels:
    26. app.kubernetes.io/component: prometheus
    27. app.kubernetes.io/instance: k8s
    28. app.kubernetes.io/name: prometheus
    29. app.kubernetes.io/part-of: kube-prometheus
    30. app.kubernetes.io/version: 2.36.1
    31. podMonitorNamespaceSelector: {}
    32. podMonitorSelector: {}
    33. probeNamespaceSelector: {}
    34. probeSelector: {}
    35. replicas: 2
    36. resources:
    37. requests:
    38. memory: 400Mi
    39. ruleNamespaceSelector: {}
    40. ruleSelector: {}
    41. securityContext:
    42. fsGroup: 2000
    43. runAsNonRoot: true
    44. runAsUser: 1000
    45. serviceAccountName: prometheus-k8s
    46. serviceMonitorNamespaceSelector: {}
    47. serviceMonitorSelector: {}
    48. version: 2.36.1
    49. additionalScrapeConfigs:
    50. name: additional-configs
    51. key: prometheus-additional.yaml

  • 相关阅读:
    相似度系列8:unify-BARTSCORE: Evaluating Generated Text as Text Generation
    小米OPPO三星一加红魔全机型解锁BL详细教程合集-ROOT刷机必要操作
    云原生是整个信息化行业的未来,一文彻底搞懂云原生
    Mygin中间件优化及logger日志中间件
    网页图标工具
    记一次etcd全局锁使用不当导致的事故
    TCP/IP协议网络层
    Django之主键外键详解
    Vue学习-computed和watch的区别
    云计算、大数据技术的智慧工地,实现对建筑工地实时监测、管理和控制的一种新型建筑管理方式
  • 原文地址:https://blog.csdn.net/knight_zhou/article/details/126233487