如何使用virtualservice公开grafana prometheus和kiali等仪表板?

Xuy*_*Shi 2 grafana kubernetes istio istio-kiali

<dashboard>.foobar.com我已经毫无问题地暴露了我的仪表板,现在我正在尝试将上面提到的仪表板公开给www.foobar.com/dashboard/<kiali> 我,我已经使用一个简单的 .net 后端容器进行了测试,并设置了此 VS:

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
Run Code Online (Sandbox Code Playgroud)

然后我有: 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
Run Code Online (Sandbox Code Playgroud)

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

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

Xuy*_*Shi 6

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

我已经解决了这个问题:

首先,VirtualServive 是正确的,但请记住在写入部分添加引号:

    rewrite:
      uri: "/"
Run Code Online (Sandbox Code Playgroud)

并且前缀部分需要用/

  - name: kubernetes-dashboard
    match:
    - uri:
        prefix: "/kubernetes/"
Run Code Online (Sandbox Code Playgroud)

窍门来了,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'
Run Code Online (Sandbox Code Playgroud)

而在prometheus中,也有类似的:

- 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=/'
Run Code Online (Sandbox Code Playgroud)

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

  - name: kiali-dashboard
    match:
    - uri:
        prefix: /kiali/
    rewrite:
      uri: "/kiali/"
Run Code Online (Sandbox Code Playgroud)