进入路由规则以访问Prometheus服务器

时间:2020-04-09 12:20:53

标签: kubernetes prometheus kubernetes-ingress

我已经在kubernetes(1.17.3)上部署了prometheus服务器(2.13.1),我可以在http://my.prom.com:9090上访问它

但是我想在http://my.prom.com:9090/prometheus上访问它,因此我添加了以下入口规则,但没有 工作

首次尝试:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/app-root: /prometheus
  name: approot
  namespace: default
spec:
  rules:
  - host: my.prom.com
    http:
      paths:
      - backend:
          serviceName: prometheus-svc
          servicePort: 9090
        path: /

这会导致404错误

第二次尝试:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: my.prom.com
    http:
      paths:
      - backend:
          serviceName: prometheus-svc
          servicePort: 9090
        path: /prometheus(/|$)(.*)

现在,当我在浏览器中访问URL http://my.prom.com:9090/prometheus时,它更改为http://my.prom.com:9090/graph并显示404错误

2 个答案:

答案 0 :(得分:3)

Prometheus无法知道您要实现的目标,这就是为什么它将重定向到未知目标的原因。

您必须告诉普罗米修斯接受新路径上的流量,如herehere所示。

突出显示第二个链接,您必须在Prometheus部署中包括- "--web.route-prefix=/"- "--web.external-url=http://my.prom.com:9090/prometheus"

然后,我不得不修改 prometheus 部署以接受流量 在新的路径 / prom )上。 Securing Prometheus API and UI Endpoints Using Basic Auth中对此进行了介绍 文档:

在您的环境中,它应如下所示:

> grep web deploy.yaml 
            - "--web.enable-lifecycle"
            - "--web.route-prefix=/"
            - "--web.external-url=http://my.prom.com:9090/prometheus"

答案 1 :(得分:0)

添加deploy-prometheus.yml

args:
    - --web.enable-lifecycle
    - --web.route-prefix=/
    - --web.external-url=https://localhost:9090/prometheus/

在VirtualService中,Prometheus

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: prometheus-vs
  namespace: istio-system
spec:
  hosts:
  - "*"
  gateways:
  - prometheus-gateway
  http:
    - match:
      - uri:
          prefix: /prometheus/
      rewrite:
        uri: /
      route:
      - destination:
          host: prometheus
          port:
            number: 9090