Skip to content

antony@notes:~/kubernetes$ cat "Quick-Start-Istio-with-ambient-mode.md"

Quick Start Istio with ambient mode

2025-08-29· kubernetes

Quick Start Istio with ambient mode

Step 1: 下載 Istio CLI

curl -L https://istio.io/downloadIstio | sh -
cd istio-1.26.1
export PATH=$PWD/bin:$PATH

檢查是否能執行 istioctl

istioctl version

命令執行結果 :

Istio is not present in the cluster: no running Istio pods in namespace "istio-system"
client version: 1.26.1

在此階段,Istio 尚未安裝到您的叢集中,因此您會看到沒有任何 Pod 處於 Ready 狀態。

Step2: Install Istio on to your cluster

istioctl 支援多種設定範本,這些範本包含不同的預設選項,並可依照您的生產需求進行自訂。ambient 模式的支援已包含在 ambient 範本中。使用以下指令安裝 Istio:

istioctl install --set profile=ambient --skip-confirmation

命令執行結果 :

        |\
        | \
        |  \
        |   \
      /||    \
     / ||     \
    /  ||      \
   /   ||       \
  /    ||        \
 /     ||         \
/______||__________\
____________________
  \__       _____/
     \_____/

✔ Istio core installed ⛵️                                                                              
✔ Istiod installed 🧠
✔ CNI installed 🪢
✔ Ztunnel installed 🔒
✔ Installation complete
The ambient profile has been installed successfully, enjoy Istio without sidecars!

檢查 Istio pods 狀態是否正常

kubectl -n istio-system get pods

命令執行結果 :

NAME                      READY   STATUS    RESTARTS   AGE
istio-cni-node-bc4fx      1/1     Running   0          8m34s
istio-cni-node-kww8q      1/1     Running   0          8m34s
istio-cni-node-qhvtt      1/1     Running   0          8m34s
istiod-799b8c5498-gpqs6   1/1     Running   0          8m44s
ztunnel-2jr6q             1/1     Running   0          8m22s
ztunnel-bnvps             1/1     Running   0          8m22s
ztunnel-hjlch             1/1     Running   0          8m22s

Step3: Install the Kubernetes Gateway API CRDs

接下來將使用 Kubernetes Gateway API 來設定流量路由。

請注意,大多數 Kubernetes 叢集預設並未安裝 Kubernetes Gateway API 的 CRD,因此在使用 Gateway API 之前,請先確保這些 CRD 已安裝:

kubectl get crd gateways.gateway.networking.k8s.io &> /dev/null || \
  kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.3.0/standard-install.yaml

檢查 CRD 是否安裝成功

kubectl get -f https://github.com/kubernetes-sigs/gateway-api/rel
eases/download/v1.3.0/standard-install.yaml

命令執行結果 :

NAME                                        CREATED AT
gatewayclasses.gateway.networking.k8s.io    2025-06-02T06:02:07Z
gateways.gateway.networking.k8s.io          2025-06-02T06:02:07Z
grpcroutes.gateway.networking.k8s.io        2025-06-02T06:02:07Z
httproutes.gateway.networking.k8s.io        2025-06-02T06:02:07Z
referencegrants.gateway.networking.k8s.io   2025-06-02T06:02:07Z

實作 Bookinfo Application

Before you begin

此範例部署了一個由四個獨立的微服務組成的範例應用程序,用於演示各種 Istio 功能。

該應用程式會顯示有關一本書的資訊,類似於線上書店的單一目錄條目。頁面上會顯示書籍的描述、書籍細節(ISBN、頁數等等),以及一些書評。

Bookinfo 應用程式拆分為四個獨立的微服務:

  • productpage:productpage 微服務會呼叫 details 和 reviews 微服務,來填充頁面內容。
  • details:details 微服務包含書籍的基本資訊。
  • reviews:reviews 微服務包含書評,並且會呼叫 ratings 微服務。
  • ratings:ratings 微服務則包含書評所搭配的書籍評分資訊。

其中,reviews 微服務有三個版本:

  1. 版本 v1 不會呼叫 ratings 服務。
  2. 版本 v2 會呼叫 ratings 服務,並將每個評分顯示為 1 到 5 顆黑色星星。
  3. 版本 v3 會呼叫 ratings 服務,並將每個評分顯示為 1 到 5 顆紅色星星。

應用程式的端到端架構如下所示。

image

該應用程式是多語言(polyglot)實作,也就是說,微服務是用不同程式語言編寫的。值得注意的是,這些服務本身並不依賴 Istio,但由於服務數量眾多、所使用的語言多樣,且 reviews 服務還有多個版本,因此成為一個頗具吸引力的服務網格示例。

Deploying the application

首先部署應用程式:

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

若要驗證應用程式是否正在執行,請檢查 pod 的狀態:

kubectl get pods

執行結果 :

NAME                              READY   STATUS    RESTARTS   AGE
details-v1-766844796b-2d7qd       1/1     Running   0          96s
productpage-v1-54bb874995-g8d4b   1/1     Running   0          95s
ratings-v1-5dc79b6bcd-zb28h       1/1     Running   0          95s
reviews-v1-598b896c9d-4hmrj       1/1     Running   0          95s
reviews-v2-556d6457d-r6q75        1/1     Running   0          95s
reviews-v3-564544b4d6-zmvzj       1/1     Running   0          95s

Deploy and configure the ingress gateway

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

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

預設情況下,Istio 會為 Gateway 建立一個 LoadBalancer 類型的 Service。由於您會透過隧道訪問此 Gateway,因此不需要 LoadBalancer,請將 Service 類型改為 ClusterIP,方法是為 Gateway 加上註解:

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 顯示為已「PROGRAMMED」後再繼續。