在 productpage 上启用 Istio
正如您在上一个模块中看到的,Istio 通过提供更有效地操作微服务的功能来增强 Kubernetes。
在本模块中,您将在单个微服务 productpage
上启用 Istio。应用程序的其余部分将继续像以前一样运行。请注意,您可以逐步启用 Istio,一次启用一个微服务。Istio 对微服务是透明启用的。您无需更改微服务代码或中断您的应用程序,它将继续运行并为用户请求提供服务。
应用默认目标规则
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/networking/destination-rule-all.yaml
重新部署启用了 Istio 的
productpage
微服务$ curl -s https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/platform/kube/bookinfo.yaml | istioctl kube-inject -f - | sed 's/replicas: 1/replicas: 3/g' | kubectl apply -l app=productpage,version=v1 -f - deployment.apps/productpage-v1 configured
访问应用程序的网页并验证应用程序是否继续工作。Istio 的添加没有更改原始应用程序的代码。
检查
productpage
的 Pod,您会发现现在每个副本都有两个容器。第一个容器是微服务本身,第二个容器是附加到它的边车代理。$ kubectl get pods details-v1-68868454f5-8nbjv 1/1 Running 0 7h details-v1-68868454f5-nmngq 1/1 Running 0 7h details-v1-68868454f5-zmj7j 1/1 Running 0 7h productpage-v1-6dcdf77948-6tcbf 2/2 Running 0 7h productpage-v1-6dcdf77948-t9t97 2/2 Running 0 7h productpage-v1-6dcdf77948-tjq5d 2/2 Running 0 7h ratings-v1-76f4c9765f-khlvv 1/1 Running 0 7h ratings-v1-76f4c9765f-ntvkx 1/1 Running 0 7h ratings-v1-76f4c9765f-zd5mp 1/1 Running 0 7h reviews-v2-56f6855586-cnrjp 1/1 Running 0 7h reviews-v2-56f6855586-lxc49 1/1 Running 0 7h reviews-v2-56f6855586-qh84k 1/1 Running 0 7h curl-88ddbcfdd-cc85s 1/1 Running 0 7h
Kubernetes 以透明且增量的方式用启用了 Istio 的 Pod 替换了
productpage
的原始 Pod,执行了 滚动更新。只有当新的 Pod 开始运行时,Kubernetes 才会终止旧的 Pod,并且它会透明地将流量逐个切换到新的 Pod。也就是说,在启动新 Pod 之前,它不会终止多个 Pod。所有这些都是为了防止应用程序中断,以便它在注入 Istio 期间继续工作。检查
productpage
的 Istio 边车的日志$ kubectl logs -l app=productpage -c istio-proxy | grep GET ... [2019-02-15T09:06:04.079Z] "GET /details/0 HTTP/1.1" 200 - 0 178 5 3 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" "18710783-58a1-9e5f-992c-9ceff05b74c5" "details:9080" "172.30.230.51:9080" outbound|9080||details.tutorial.svc.cluster.local - 172.21.109.216:9080 172.30.146.104:58698 - [2019-02-15T09:06:04.088Z] "GET /reviews/0 HTTP/1.1" 200 - 0 379 22 22 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" "18710783-58a1-9e5f-992c-9ceff05b74c5" "reviews:9080" "172.30.230.27:9080" outbound|9080||reviews.tutorial.svc.cluster.local - 172.21.185.48:9080 172.30.146.104:41442 - [2019-02-15T09:06:04.053Z] "GET /productpage HTTP/1.1" 200 - 0 5723 90 83 "10.127.220.66" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" "18710783-58a1-9e5f-992c-9ceff05b74c5" "tutorial.bookinfo.com" "127.0.0.1:9080" inbound|9080|http|productpage.tutorial.svc.cluster.local - 172.30.146.104:9080 10.127.220.66:0 -
输出您的命名空间名称。您需要它来在 Istio 仪表盘中识别您的微服务
$ echo $(kubectl config view -o jsonpath="{.contexts[?(@.name == \"$(kubectl config current-context)\")].context.namespace}") tutorial
使用您之前在
/etc/hosts
文件中设置的自定义 URL 检查 Istio 仪表盘 。http://my-istio-dashboard.io/dashboard/db/istio-mesh-dashboard
在左上角的下拉菜单中,选择“Istio 网格仪表盘”。
从左上角的下拉菜单中选择 Istio 网格仪表盘 注意来自您命名空间的
productpage
服务,其名称应为productpage.<您的命名空间>.svc.cluster.local
。Istio 网格仪表盘 在“Istio 网格仪表盘”的“服务”列下,单击
productpage
服务。Istio 服务仪表盘,已选择“productpage” 向下滚动到“服务工作负载”部分。观察仪表盘图表是否已更新。
Istio 服务仪表盘
这是在单个微服务上应用 Istio 的直接好处。您可以接收进出微服务的流量日志,包括时间、HTTP 方法、路径和响应代码。您可以使用 Istio 仪表盘监控您的微服务。
在接下来的模块中,您将了解 Istio 可以为您的应用程序提供的功能。虽然某些 Istio 功能在应用于单个微服务时是有益的,但您将学习如何在整个应用程序上应用 Istio 以发挥其全部潜力。
您已准备好 在所有微服务上启用 Istio。