如何使用 virtualservice 公开诸如 grafana prometheus 和 kiali 之类的仪表板?

问题描述

我的仪表板暴露给 <dashboard>.foobar.com 没有问题,现在我尝试将上述仪表板暴露给 www.foobar.com/dashboard/<kiali> 我已经用这个 VS 设置的简单 .net 后端容器进行了测试:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
Metadata:
  name: whatever
spec:
  hosts:
  - www.foobar.com
  gateways:
  - some-gateway
  http:
  - match:
    - uri:
        prefix: /bla
    rewrite:
      uri: " "
    route:
    - destination:
        port:
          number: 1234
        host: dummy-service

然后我有foobar.com/bla/api/hello -> dummyservice/api/hello foobar.com/bla/api/deeper/hello -> dummyservice/api/deeper/hello 这很好。 但是,如果我将相同的内容应用于这些仪表板,则没有任何效果! 这是我的仪表板设置:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
Metadata:
  name: dashboards
  namespace: istio-system
spec:
  hosts:
  - www.foobar.com
  gateways:
  - default/somegateway
  http:
  - name: grafana
    match:
    - uri:
        prefix: /dashboards/grafana
    rewrite:
      uri: /
    route:
    - destination:
        port:
          number: 80
        host: grafana.grafana.svc.cluster.local
  - name: prometheus
    match:
    - uri:
        prefix: /dashboards/prometheus
    rewrite:
      uri: "/"
    route:
    - destination:
        port:
          number: 9089
        host: prometheus-server.prometheus.svc.cluster.local
  - name: kubernetes-dashboard
    match:
    - uri:
        prefix: "/dashboards/kubernetes"
    rewrite:
      uri: " "
    route:
    - destination:
        port:
          number: 8443
        host: kubernetes-dashboard.kubernetes-dashboard.svc.cluster.local
  - name: kubernetes-dashboard
    match:
    - uri:
        prefix: "/dashboards/kiali/"
    rewrite:
      uri: /
    route:
    - destination:
        port:
          number: 20001
        host: kiali.istio-system.svc.cluster.local

正如有人提到的,/ 存在一个已知问题,因此您可以看到我对它们都有 rewrite。但仍然没有任何作用。 我得到了其中大部分的 404,grafana 将我重定向www.foobar.com/login

有人做过吗?我在想这些仪表板可能包含在前端,所以它不像我的 .net 后端容器那么简单?

解决方法

如果有人有同样的问题,请看这里:

我已经解决了这个问题:

所以首先,VirtualSerive 是正确的,但记得在写部分添加引号:

    rewrite:
      uri: "/"

前缀部分需要用 / 结束

  - name: kubernetes-dashboard
    match:
    - uri:
        prefix: "/kubernetes/"

诀窍来了,prometheus 和 grafana 被设计为在 root url 上工作。但是,它可以在 deployment.yaml 例如,我希望我的 grafana 和 prometheus 分别在 www.foobar.com/grafana/www.foobar.com/prometheus 工作。 在 grafana deployment.yaml 中,我们需要指定:

          env:
            - name: GF_SERVER_ROOT_URL
              value: 'http://localhost:3000/grafana/'
            - name: GF_SERVER_DOMAIN
              value: localhost
            - name: GF_SERVER_SERVE_FROM_SUB_PATH
              value: 'true'

在普罗米修斯中,它有类似的:

- name: prometheus-server
    image: 'quay.io/prometheus/prometheus:v2.24.0'
    args:
      - '--web.enable-lifecycle'
      - '--web.external-url=https://localhost:9090/prometheus/'
      - '--web.route-prefix=/'

对于kiali,诀窍在于虚拟服务,你必须将其重写为/kiali/

  - name: kiali-dashboard
    match:
    - uri:
        prefix: /kiali/
    rewrite:
      uri: "/kiali/"