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完成。