基于k8s集群部署prometheus监控ingress nginx

2021/4/17 7:27:35

本文主要是介绍基于k8s集群部署prometheus监控ingress nginx,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目录

  • 基于k8s集群部署prometheus监控ingress nginx
    • 1、背景和环境概述
    • 2、修改prometheus配置
    • 3、检查是否生效
    • 4、配置grafana图形


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



这篇关于基于k8s集群部署prometheus监控ingress nginx的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程