1、bookinfo 架构介绍
bookinfo 是 istio 的学习样例,通过 bookinfo 你可以对 istio 提供的路由、遥测等功能有更加深入的理解。下图是 bookinfo 在没有嵌入 istio 前的物理架构图:
bookinfo 是一个在线书店应用,该应用由 4 个微服务组成,分别为 Product page、Reviews、Details 和 Ratings。为了表现 istio 的无侵入性,这 4 个微服务分别由 python、java、ruby 和 node 开发。下面分别说明如下:
Product page:聚合服务,内容由 Reviews 和 Details 内容聚合而成
Details: 图书详情服务
Reviews: 图书评价服务(多版本)。它也是一个聚合服务,聚合了 Ratings
Ratings: 图书预订排名服务
下图是 bookinfo 嵌入 istio 后的物理架构图:
该架构图演示了嵌入 istio 后 bookinfo 的每个微服务都会新增一个 Envoy,这个 Envoy 就是所谓的 sidecar,它会接管跟它配对的微服务的所有网络进、出口流量。其实 Envoy(sidecar)的作用就像你的手机,它正在逐渐把你变成哑巴、聋子和植物人,它承接了你所有的信息入口和出口,某些别有用心的人和组织通过对手机进行监控、遥测、路由等控制,起到控制你的思维、舆论导向、审美爱好等目的。
2、bookinfo 配置与部署
2.1 配置istio自动注入
因为 bookinfo 会启动多个 pod,每次手动注入 sidecar 会特别繁琐,因此我们使用批注入的方式
kubectl create ns test kubectl label ns test istio-injection=enabled kubectl get ns test --show-labels
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml -n test
执行如下命令查看 bookinfo 的 service 列表:
kubectl get svc -n test
执行如下命令查看 bookinfo 的 pod 列表:
kubectl get pod -n test
2.3 验证 bookinfo 部署情况
在服务列表中寻找 productpage 服务,然后使用 curl 命令验证服务是否发布成功。
kubectl get svc -n test curl http://10.43.53.159:9080 | grep -o "<title>.*</title>"
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml -n test #定义 bookinfo 入口网关 kubectl get gateways.networking.istio.io -n test #确认网关已创建
kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}' # 获取 INGRESS_HOST kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}' #获取 INGRESS_PORT
根据此 host 和 port,打开浏览器进行访问,多刷新几次页面,你会发现 bookinfo 应用使用到的多个 reviews 版本,如下所示:
http://192.168.0.116:30066/productpage #ip加端口会报404
正好可以对应到 pod 信息:
./istio-1.4.5/samples/bookinfo/platform/kube/cleanup.sh
执行如下命令验证你是否成功卸载:
kubectl get virtualservices.networking.istio.io -n test kubectl get destinationrules.networking.istio.io -n test kubectl get gateways.networking.istio.io -n test kubectl get pod -n test