十三 Istio:Istio项目实际案例——Online Boutique( 三 )

创建 Istio 资源:
[root@k8scloude1 microservices-demo]# pwd/root/online-boutique/microservices-demo[root@k8scloude1 microservices-demo]# ls istio-manifests/allow-egress-googleapis.yamlfrontend-gateway.yamlfrontend.yaml[root@k8scloude1 microservices-demo]# kubectl apply -f ./istio-manifestsserviceentry.networking.istio.io/allow-egress-googleapis createdserviceentry.networking.istio.io/allow-egress-google-metadata createdgateway.networking.istio.io/frontend-gateway createdvirtualservice.networking.istio.io/frontend-ingress createdvirtualservice.networking.istio.io/frontend created部署了一切后,我们就可以得到入口网关的 IP 地址并打开前端服务:
[root@k8scloude1 microservices-demo]# INGRESS_HOST="$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"[root@k8scloude1 microservices-demo]# echo "$INGRESS_HOST"192.168.110.190[root@k8scloude1 microservices-demo]# kubectl get service -n istio-system istio-ingressgateway -o wideNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGESELECTORistio-ingressgatewayLoadBalancer10.107.131.65192.168.110.19015021:30093/TCP,80:32126/TCP,443:30293/TCP,31400:30628/TCP,15443:30966/TCP27dapp=istio-ingressgateway,istio=ingressgateway在浏览器中打开 INGRESS_HOST,你会看到前端服务,浏览器访问http://192.168.110.190/,如下图所示:

十三 Istio:Istio项目实际案例——Online Boutique

文章插图
我们需要做的最后一件事是删除 frontend-external 服务 。frontend-external 服务是一个 LoadBalancer 服务,它暴露了前端 。由于我们正在使用 Istio 的入口网关 , 我们不再需要这个 LoadBalancer 服务了 。
删除frontend-external服务,运行:
[root@k8scloude1 ~]# kubectl get svc | grep frontend-externalfrontend-externalLoadBalancer10.102.0.207192.168.110.19180:30173/TCP4d15h[root@k8scloude1 ~]# kubectl delete svc frontend-externalservice "frontend-external" deleted[root@k8scloude1 ~]# kubectl get svc | grep frontend-externalOnline Boutique 应用清单还包括一个负载发生器,它正在生成对所有服务的请求——这是为了让我们能够模拟网站的流量 。
六.部署可观察性工具6.1 部署可观察性工具接下来,我们将部署可观察性、分布式追踪、数据可视化工具 , 下面两种方法任选一种;
关于prometheus,grafana,kiali,zipkin更详细的安装方法可以查看博客《Istio(三):服务网格istio可观察性:Prometheus,Grafana,Zipkin,Kiali》https://www.cnblogs.com/renshengdezheli/p/16836943.html
#方法一:[root@k8scloude1 ~]# kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.14/samples/addons/prometheus.yaml[root@k8scloude1 ~]# kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.14/samples/addons/grafana.yaml[root@k8scloude1 ~]# kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.14/samples/addons/kiali.yaml[root@k8scloude1 ~]# kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.14/samples/addons/extras/zipkin.yaml #方法二:下载istio安装包istio-1.14.3-linux-amd64.tar.gz安装分析工具[root@k8scloude1 ~]# ls istio* -distio-1.14.3istio-1.14.3-linux-amd64.tar.gz[root@k8scloude1 ~]# cd istio-1.14.3/[root@k8scloude1 addons]# pwd/root/istio-1.14.3/samples/addons[root@k8scloude1 addons]# lsextrasgrafana.yamljaeger.yamlkiali.yamlprometheus.yamlREADME.md[root@k8scloude1 addons]# kubectl apply -f prometheus.yaml[root@k8scloude1 addons]# kubectl apply -f grafana.yaml[root@k8scloude1 addons]# kubectl apply -f kiali.yaml [root@k8scloude1 addons]# ls extras/prometheus-operator.yamlprometheus_vm_tls.yamlprometheus_vm.yamlzipkin.yaml[root@k8scloude1 addons]# kubectl apply -f extras/zipkin.yaml
如果你在安装 Kiali 的时候发现以下错误 No matches for kind "MonitoringDashboard" in version "monitoring.kiali.io/v1alpha1" 请重新运行以上命令 。
prometheus,grafana,kiali , zipkin被安装在istio-system命名空间下 , 我们可以使用 getmesh istioctl dashboard kiali 打开 Kiali界面 。
我们使用另外一种方法打开Kiali界面:
#可以看到prometheus,grafana,kiali , zipkin被安装在istio-system命名空间下[root@k8scloude1 addons]# kubectl get pod -n istio-systemNAMEREADYSTATUSRESTARTSAGEgrafana-6c5dc6df7c-cnc9w1/1Running227histio-egressgateway-58949b7c84-k7v6f1/1Running810distio-ingressgateway-75bc568988-69k8j1/1Running63d21histiod-84d979766b-kz5sd1/1Running1410dkiali-5db6985fb5-8t77v1/1Running03m25sprometheus-699b7cc575-dx6rp2/2Running82d21hzipkin-6cd5d58bcc-hxngj1/1Running117h#可以看到kiali这个service的类型为ClusterIP,外部环境访问不了[root@k8scloude1 addons]# kubectl get service -n istio-systemNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGEgrafanaNodePort10.100.151.232<none>3000:31092/TCP27histio-egressgatewayClusterIP10.102.56.241<none>80/TCP,443/TCP10distio-ingressgatewayLoadBalancer10.107.131.65192.168.110.19015021:30093/TCP,80:32126/TCP,443:30293/TCP,31400:30628/TCP,15443:30966/TCP10distiodClusterIP10.103.37.59<none>15010/TCP,15012/TCP,443/TCP,15014/TCP10dkialiClusterIP10.109.42.120<none>20001/TCP,9090/TCP7m42sprometheusNodePort10.101.141.187<none>9090:31755/TCP2d21htracingClusterIP10.101.30.10<none>80/TCP17hzipkinNodePort10.104.85.78<none>9411:30350/TCP17h#修改kiali这个service的类型为NodePort,这样外部环境就可以访问kiali了#把type: ClusterIP 修改为 type: NodePort即可[root@k8scloude1 addons]# kubectl edit service kiali -n istio-systemservice/kiali edited#现在kiali这个service的类型为NodePort,浏览器输入物理机ip:30754即可访问kiali网页了[root@k8scloude1 addons]# kubectl get service -n istio-systemNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGEgrafanaNodePort10.100.151.232<none>3000:31092/TCP27histio-egressgatewayClusterIP10.102.56.241<none>80/TCP,443/TCP10distio-ingressgatewayLoadBalancer10.107.131.65192.168.110.19015021:30093/TCP,80:32126/TCP,443:30293/TCP,31400:30628/TCP,15443:30966/TCP10distiodClusterIP10.103.37.59<none>15010/TCP,15012/TCP,443/TCP,15014/TCP10dkialiNodePort10.109.42.120<none>20001:30754/TCP,9090:31573/TCP8m42sprometheusNodePort10.101.141.187<none>9090:31755/TCP2d21htracingClusterIP10.101.30.10<none>80/TCP17hzipkinNodePort10.104.85.78<none>9411:30350/TCP17h

推荐阅读