[英]Kubernetes - Prometheus Missing All NGINX Ingress Metrics?
[英]Nginx ingress controller not giving metrics for prometheus
我正在尝试部署一个 nginx 入口控制器,该控制器可以使用 prometheus 进行监控,但是我遇到了一个问题,似乎没有像我在网上找到的大多数帖子和文档那样创建指标 pod。
我正在使用 helm 部署入口控制器并使用 CLI 参数来启用指标。
helm install ingress stable/nginx-ingress --set controller.metrics.enabled=true
这是我的入口文件
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
# add an annotation indicating the issuer to use.
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-dev"
# needed to allow the front end to talk to the back end
nginx.ingress.kubernetes.io/cors-allow-origin: "https://app.domain.com"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, PUT, POST, DELETE, PATCH, OPTIONS"
# needed for monitoring
prometheus.io/scrape: "true"
prometheus.io/port: "10254"
name: dev-ingress
namespace: development
spec:
rules:
- host: api.<domain>.com
http:
paths:
- backend:
serviceName: api
servicePort: 8090
path: /
tls: # < placing a host in the TLS config will indicate a certificate should be created
- hosts:
- api.<domai>.com
secretName: dev-ingress-cert # < cert-manager will store the created certificate in this secre
如果这会有所不同,我将使用带有以下命令的 prometheus 操作员舵图。
helm install monitoring stable/prometheus-operator --namespace=monitoring
所有命名空间都已经存在,所以这不应该成为问题,至于我在很多地方看到的开发与监控命名空间,这是可以接受的,所以我使用它来让事情更容易弄清楚发生了什么。
我会按照本指南为 Nginx 入口控制器设置监控。 我相信您缺少的是prometheus.yaml ,它定义了 Nginx 入口控制器的抓取配置和RBAC ,以便普罗米修斯能够抓取 Nginx 入口控制器指标。
编辑:注释 nginx 入口控制器 pod
kubectl annotate pods nginx-ingress-controller-pod prometheus.io/scrape=true -n ingress-nginx --overwrite
kubectl annotate pods nginx-ingress-controller-pod prometheus.io/port=10254 -n ingress-nginx --overwrite
我没有使用 helm 而是使用清单和方法 POD 注释来安装 Prometheus。 我遵循官方文档,但也看不到指标。
我相信部署清单有一些问题。 注解不应放在 Deployment 级别,而应放在 pod 级别
apiVersion: v1
kind: Deployment
..
spec:
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "10254"
label:
...
ports:
- name: prometheus
containerPort: 10254
..
此外,我已经确认在使用清单部署时默认启用 Nginx 的指标。 不需要额外的步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.