【问题标题】:Expose grafana publicly using istio使用 istio 公开 grafana
【发布时间】:2020-12-20 16:14:43
【问题描述】:

我们正在使用 Prometheus 运算符,我们需要使用 istio 公开(外部)公开 Grafana, https://github.com/helm/charts/tree/master/stable/prometheus-operator

通常,当我有需要通过 istio 公开公开的应用程序时,我会在我的微服务中添加类似以下的内容它可以工作并在外部公开。

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: po-svc
  namespace: po
spec:
  ports:
    - name: http
      port: 3000
      targetPort: 3000
  selector:
    app: myapp  //I take the name from deployment.yaml --in the chart NOT SURE WHICH VALUE I SHOULD TAKE FROM THE CHART---

并添加一个虚拟服务

virtualservice.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: po-virtualservice
  namespace: po
spec:
  gateways:
    - gw-system.svc.cluster.local
  hosts:
    - po.eu.trial.appos.cloud.mvn
  http:
    - route:
        - destination:
            host: po-svc
            port:
              number: 3000

然后我可以公开访问我的应用程序。

现在我想从 prometheus 操作符图表中为 Grafana 做同样的事情

values.yaml中有服务入口

https://github.com/helm/charts/blob/master/stable/prometheus-operator/values.yaml#L576 但是不确定它是否应该替换service.yaml,如果是的话,如何填充像app: myapp 这样的数据(在常规应用程序中我从deployment.yaml 的“名称”字段中获取)作为服务具有的grafana参考 Grafana 应用

另外,在virutalservice.yaml中有一个对service的引用(主机:po-svc)

我的问题是:我应该如何填写这两个值并能够 使用 istio 暴露 Grafana 吗?

顺便说一句,如果我将values from the chart 更改为LoadBalancer 如下所示,我将获得一个公共 url 以访问外部,但是我想通过 istio 公开它。

  service:
    portName: service
    type: LoadBalancer

更新

我创建了以下虚拟服务

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: po-virtualservice
  namespace: po
spec:
  gateways:
    - gw-system.svc.cluster.local
  hosts:
    - po.eu.trial.appos.cloud.mvn
  http:
    - route:
        - destination:
            host: po-grafana. // This is the name of the service that promethues operator created when applying the chart .
            port:
              number: 3000

并更新values.yaml,如下所示

  service:
    portName: service
    port: 3000
    targetPort: 3000

现在,当我在浏览器中点击应用程序 url (po.eu.trial.appos.cloud.mvn) 时出现错误

upstream connect error or disconnect/reset before headers. reset reason: connection termination 知道可能是什么问题吗?我应该如何追踪这个问题?

我认为(不确定 100%)我可能在 chart 中的服务配置中遗漏了某些内容,但不确定是什么...

我发现这个帖子有类似的错误:(但不确定我们是否有同样的问题)

https://github.com/istio/istio/issues/19966

但不确定如何将名称端口添加到 chart yaml 服务定义

【问题讨论】:

  • 您的 istio 网关是否部署在与名称 egw-system.svc.cluster.local 相同的命名空间中?你的 (PeerAuthentication) spec.mtls.mode 使用 grafana 的命名空间是什么?
  • @FL3SH - 是的,当然,我们在其他可以工作并公开公开的应用程序上使用此网关,考虑 PeerAuthentication 不确定它是什么意思,我该如何检查,我应该运行任何k8s命令能实现吗?但不确定它与我的问题有什么关系:)
  • 如果您使用的是spec.mtls.mode: stric,您必须为此服务禁用mTLS
  • 你自己创建了什么服务,命名为po-svc,promethus-operator 应该为 grafana 创建服务?
  • 你能从部署 promtheus-operator 的命名空间中添加来自 kiali 的屏幕截图吗?另请检查您现在的 mTLS 配置是什么。

标签: kubernetes grafana kubernetes-helm istio prometheus-operator


【解决方案1】:

1.7.0 版本的 istio 有一个工作示例

istioctl version
client version: 1.7.0
control plane version: 1.7.0
data plane version: 1.7.0 (1 proxies)

1.我用helm fetch获取prometheus算子。

helm fetch stable/prometheus-operator --untar

2.我在 values.yaml 中更改了这些。

格拉法纳Service.

service:
  portName: http-service
  port: 3000
  targetPort: 3000

格拉法纳host.

hosts:
  - grafana.domain.com

3.我已经创建了po命名空间并安装了prometheus operator

kubectl create namespace po
helm install prometheus-operator ./prometheus-operator -n po

4.我已经检查了grafana服务名称

kubectl get svc -n po
prometheus-operator-grafana                    ClusterIP

5.我在 istio 使用了下面的 yamls,使用 grafana 服务名称 prometheus-operator-grafana 作为我的虚拟服务和目标规则主机。

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: grafana-gateway
  namespace: po
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http-grafana
      protocol: HTTP
    hosts:
    - "grafana.domain.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: grafana-vs
  namespace: po
spec:
  hosts:
  - "grafana.domain.com"
  gateways:
  - grafana-gateway
  http:
  - route:
    - destination:
        host: prometheus-operator-grafana.po.svc.cluster.local
        port:
          number: 3000
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: grafana
  namespace: po
spec:
  host: prometheus-operator-grafana.po.svc.cluster.local
  trafficPolicy:
    tls:
      mode: DISABLE

5.使用 curl 测试,它是 302 而不是我们必须登录的 200。

curl -v -H "host: grafana.domain.com" xx.xx.xxx.xxx/

GET / HTTP/1.1
> Host: grafana.domain.com
> User-Agent: curl/7.64.0
> Accept: */*
>
< HTTP/1.1 302 Found

让我知道它是否有效或您有任何其他问题。可能你使用的1.4.3版本有问题。

【讨论】:

  • 你太棒了!!!我刚刚将 portName 从 portName: service 更改为 portName: http-service 并且可以正常工作!
  • 你是怎么找到这个属性值的?
  • 这是 istio documentation 中的要求之一,命名服务端口:可以选择命名服务端口以显式指定协议。有关详细信息,请参阅Protocol Selection
  • 谢谢你真的帮了我!
猜你喜欢
  • 1970-01-01
  • 2019-12-12
  • 1970-01-01
  • 2019-04-16
  • 2020-01-23
  • 2019-08-12
  • 2020-08-04
  • 2019-12-13
  • 2020-06-14
相关资源
最近更新 更多