基於k8s集群部署prometheus監控ingress nginx


基於k8s集群部署prometheus監控ingress nginx

1、背景和環境概述

本文中涉及到的環境中、prometheus監控和grafana基本環境已部署好。
nginx ingress controller的官方文檔中對監控有相應描述
https://kubernetes.github.io/ingress-nginx/user-guide/monitoring/

2、修改prometheus配置

修改prometheus的配置,增加對ingress nginx的監控配置,可按照官方yaml
進行修改:

vim prometheus-configmap.yaml
- job_name: 'ingress-nginx-endpoints'
  kubernetes_sd_configs:
  - role: pod
    namespaces:
      names:
      - ingress-nginx
  relabel_configs:
  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
    action: keep
    regex: true
  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme]
    action: replace
    target_label: __scheme__
    regex: (https?)
  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
    action: replace
    target_label: __metrics_path__
    regex: (.+)
  - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
    action: replace
    target_label: __address__
    regex: ([^:]+)(?::\d+)?;(\d+)
    replacement: $1:$2
  - source_labels: [__meta_kubernetes_service_name]
    regex: prometheus-server
    action: drop

重新apply一下configmap

kubectl apply -f prometheus-configmap.yaml

3、檢查是否生效

打開prometheus界面,查看target中是否有ingress nginx的相關記錄

檢查查詢取值

4、配置grafana圖形

在grafana圖形中導入模板,模板可以按照官方給出的json文件操作,下載此json文件,在grafana中導入即可

查看圖形

至此,prometheus監控ingress nginx完成。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM