在 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,並查看現在每個副本都有兩個容器。第一個容器是微服務本身,第二個容器是附加到它的 Sidecar 代理。$ 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,以透明且遞增的方式執行滾動更新。 Kubernetes 僅在新 Pod 開始運行時才終止舊的 Pod,並且它會逐個透明地將流量切換到新的 Pod。也就是說,它不會在新 Pod 啟動之前終止多個 Pod。所有這些都是為了防止您的應用程式中斷,因此它在 Istio 注入期間可以繼續工作。檢查
productpage
的 Istio Sidecar 日誌$ 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 Mesh 儀表板。
從左上方下拉選單中選取 Istio Mesh 儀表板 請注意您命名空間中的
productpage
服務,它的名稱應該是productpage.<您的命名空間>.svc.cluster.local
。Istio Mesh 儀表板 在Istio Mesh 儀表板中,於
Service
欄位下,點選productpage
服務。Istio 服務儀表板,已選取 `productpage` 向下捲動到服務工作負載區段。觀察儀表板圖表已更新。
Istio 服務儀表板
這是在單一微服務上套用 Istio 的直接好處。您會收到進出微服務的流量日誌,包括時間、HTTP 方法、路徑和回應碼。您可以使用 Istio 儀表板監控您的微服務。
在下一個模組中,您將學習 Istio 可以為您的應用程式提供的功能。雖然某些 Istio 功能在應用於單一微服務時是有益的,但您將學習如何將 Istio 應用於整個應用程式,以發揮其全部潛力。
您已準備好在所有微服務上啟用 Istio。