部署應用程式

若要探索 Istio,您將安裝範例 Bookinfo 應用程式,它由四個獨立的微服務組成,用於示範各種 Istio 功能。

Istio's Bookinfo sample application is written in many different languages
Istio 的 Bookinfo 範例應用程式是用許多不同的語言撰寫的

在本指南中,您將部署 Bookinfo 應用程式,並使用入口閘道公開 productpage 服務。

部署 Bookinfo 應用程式

首先部署應用程式

$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/platform/kube/bookinfo.yaml
$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/platform/kube/bookinfo-versions.yaml

為了驗證應用程式是否正在運行,請檢查 Pod 的狀態。

$ kubectl get pods
NAME                             READY   STATUS    RESTARTS   AGE
details-v1-cf74bb974-nw94k       1/1     Running   0          42s
productpage-v1-87d54dd59-wl7qf   1/1     Running   0          42s
ratings-v1-7c4bbf97db-rwkw5      1/1     Running   0          42s
reviews-v1-5fd6d4f8f8-66j45      1/1     Running   0          42s
reviews-v2-6f9b55c5db-6ts96      1/1     Running   0          42s
reviews-v3-7d99fd7978-dm6mx      1/1     Running   0          42s

若要從叢集外部存取 productpage 服務,您需要設定一個 Ingress Gateway。

部署和設定入口閘道

您將使用 Kubernetes Gateway API 來部署一個名為 bookinfo-gateway 的 Gateway。

$ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/gateway-api/bookinfo-gateway.yaml

預設情況下,Istio 會為 Gateway 建立一個 LoadBalancer 服務。由於我們將通過通道存取此 Gateway,因此不需要負載平衡器。通過註解 Gateway 將服務類型更改為 ClusterIP

$ kubectl annotate gateway bookinfo-gateway networking.istio.io/service-type=ClusterIP --namespace=default

若要檢查 Gateway 的狀態,請執行:

$ kubectl get gateway
NAME               CLASS   ADDRESS                                            PROGRAMMED   AGE
bookinfo-gateway   istio   bookinfo-gateway-istio.default.svc.cluster.local   True         42s

存取應用程式

您將通過剛才佈建的 Gateway 連接到 Bookinfo 的 productpage 服務。若要存取該 Gateway,您需要使用 kubectl port-forward 命令。

$ kubectl port-forward svc/bookinfo-gateway-istio 8080:80

開啟您的瀏覽器並導覽至 https://#:8080/productpage 以檢視 Bookinfo 應用程式。

Bookinfo Application
Bookinfo 應用程式

如果您重新整理頁面,您應該會看到書籍評論和評分隨著請求在 reviews 服務的不同版本之間分配而變化。

下一步

繼續下一節,將應用程式添加到網格中,並學習如何保護和視覺化應用程式之間的通訊。

這個資訊對您有幫助嗎?
您有任何改進建議嗎?

感謝您的回饋!