暴露grafana等内部组件服务

在安装完成istio后,默认状态下,集群外用户不能直接访问istio集群内的grafana等管理、监控服务。

有两种方法可以将集群内服务开放出来。一种是使用port-forward方式将本地端口流量转发到pod端口,实现集群内服务的访问;另一种方式是采用istio gateway方式,将集群内服务暴露到外网。

第一种方式(以暴露Prometheus为例,官方教程也是这种方式,这种方式极其反人类,推荐使用下面的第二种方式):

kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &

第二种方式需要将集群的默认网关服务ingressgateway的网络模式设置为LB/nodeport模式,作为代理实现对外服务。

1. 设置ingress gateway的工作模式

安装istio的时候默认就是LB的

2. 验证ingress gateway的网络模式

[root@k8s-master ~]# kubectl get svc -n istio-system
NAME                        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                                                                                      AGE
grafana                     ClusterIP      10.101.122.19    <none>        3000/TCP                                                                                                                                     11h
istio-egressgateway         ClusterIP      10.106.2.83      <none>        80/TCP,443/TCP,15443/TCP                                                                                                                     11h
istio-ingressgateway        LoadBalancer   10.110.238.41    <pending>     15020:31598/TCP,80:30299/TCP,443:31413/TCP,15029:30249/TCP,15030:32499/TCP,15031:31399/TCP,15032:32373/TCP,31400:30156/TCP,15443:30319/TCP   11h
istio-pilot                 ClusterIP      10.103.43.172    <none>        15010/TCP,15011/TCP,15012/TCP,8080/TCP,15014/TCP,443/TCP                                                                                     11h
istiod                      ClusterIP      10.105.251.21    <none>        15012/TCP,443/TCP                                                                                                                            11h
jaeger-agent                ClusterIP      None             <none>        5775/UDP,6831/UDP,6832/UDP                                                                                                                   11h
jaeger-collector            ClusterIP      10.99.197.254    <none>        14267/TCP,14268/TCP,14250/TCP                                                                                                                11h
jaeger-collector-headless   ClusterIP      None             <none>        14250/TCP                                                                                                                                    11h
jaeger-query                ClusterIP      10.110.152.152   <none>        16686/TCP                                                                                                                                    11h
kiali                       ClusterIP      10.100.252.210   <none>        20001/TCP                                                                                                                                    11h
prometheus                  ClusterIP      10.108.175.66    <none>        9090/TCP                                                                                                                                     11h
tracing                     ClusterIP      10.102.204.150   <none>        80/TCP                                                                                                                                       11h
zipkin                      ClusterIP      10.104.104.190   <none>        9411/TCP                                                                                                                                     11h

3. 查看作为边界代理的ingress-gateway的端口映射情况

上图所示,ingressgateway创建时,自动预设了一些端口映射,其中https-grafana的15301端口映射到node的31399端口,我们将15031端口关联到grafana上,集群外就用户通过访问网关所在机器的31399端口访问到grafana服务。

4. gateway方式暴露集群内服务

需要创建服务的gateway和virtual service资源如下:

执行:

特别需要注意:后面的namespaceistio-system,因为grafana等内部组件都是这个namespace的。

5. 测试grafana的连通性

参考

istio中的grafana等内部组件服务开放给集群外用户访问

最后更新于

这有帮助吗?