Prometheus Operator 公开入口路由

Prometheus Operator Expose Ingress Route

我想通过 HTTPS 通过 Internet 访问 Prometheus Operator。

我通过 HELM 部署了 Prometheus 并提供了以下自定义-vault.yml

图表版本:

 kube-prometheus-0.0.105
 nginx-ingress-0.31.0

部署:

helm install coreos/kube-prometheus --name kube-prometheus --set global.rbacEnable=false \
--namespace monitoring -f custom-vault.yml

我的期望: 我想通过 URL 浏览 Prometheus https://example.com/prometheus

我的自定义-vault.yml

prometheus:
  ingress:
    enabled: true
    annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/rewrite-target: /
    tls: 
      - secretName: tls-secret
        hosts: 
          - example.com
    hosts:
      - example.com
    paths:
      - /
  #prometheusSpec:
    #externalUrl: https://example.com/prometheus

发生了什么?

我可以到达 https://example.com/graph,但是 CSS 由于路径错误,文件没有加载。

当我尝试配置 https://example.com/prometheus/graph also CSS doesn´t work and when i click on the Frontend on Alerts then i get redireted to https://example.com/alerts 并出现 "default backend 404" 错误时。

服务的其他入口路由/Pods正在运行 Prometheus 也在工作 - 当我将端口公开给本地主机时,Prometheus 得到正确显示。

您的 url 是:“https://example.com/prometheus”,您的路径是“/”

这解释了为什么您可能有一些工作 link 而不是其他(CSS,索引...)。

如果我没记错的话你应该这样创建你的路径:

paths:
  - /prometheus/*

这表示,结合您的重写目标使用 /prometheus 作为根 url 并接受所有子 url。重写将在 pod 内重定向到 /.

更改部分

paths:
  - /

  paths:
  - prometheus:
    path: /prometheus

但是您应该记住,通过 Ingress 对象公开 Prometheus 网络 UI 需要 运行 Ingress controller

您可以在此处找到更多信息:operator-prometheus-coreos

感谢您的输入。你帮我解决了问题。不是很直接,但是给了我一个新的观点。

我是如何解决这个问题的: 我将部署从 coreos/kube-prometheus 更改为 stable/prometheus-operator

当前版本为6.11 我无法直接安装 6.11 - 我需要安装 6.0.0 并升级到 6.11

还提供了新的自定义-value.yaml

使用此设置效果非常好!

自定义-value.yaml

prometheus:
  ingress:
    enabled: true
    annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/whitelist-source-range: "{my_whitelisted_public_ip}"
      nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
    tls: 
      - secretName: tls-secret
        hosts: 
          - example.com
    hosts:
      - example.com
    paths:
      - /
  prometheusSpec:
    externalUrl: http://example.com/prometheus
    routePrefix : prometheus/

谢谢。

BR