今天要來談談 istio 很重要的一點 sidecar ,這是一個很棒的 pattern ,今天決定特別跟大家分享這個模式。

sidecar pattern

首先先照著我前天部署的那篇 『怎麼部署你第一個 application 到 k3s 裡面』,使用裡面的 first-helloworld,請動完後應該會看到這樣

$ kubectl get pods
NAME                                         READY   STATUS    RESTARTS   AGE
first-hellworld-deployment-566d79fb7-d9jpq   2/2     Running   0          11m
first-hellworld-deployment-566d79fb7-f979g   2/2     Running   0          11m
first-hellworld-deployment-566d79fb7-jr5qn   2/2     Running   0          11m

透過 kubectl describe pods {pod name} ,可以看到一個 pod 裡面有三個 container,分別是

  • istio-init
  • first-helloworld
  • istio-proxy

其中 istio-init 是用來當作 init conatiners,這是 k8s 原生提供出來的功能,有興趣可以參考官方文件

istio-arch ref

1.6版後 istio 架構大更新,所以如果是使用 1.5版之前的版本,請注意架構上有明顯的不同。

如上圖 istio 使用 proxy 就是使用 Enovy 這個東西所組成的,它是由 C++ 所撰寫的高效能網路代理工具,他負責所有服務進出的控制,下面列出我有使用它的功能

  • HTTP/2 、 gRPC 代理
  • 負載平衡
  • 動態的服務發現
  • health check
  • 各種流量指標分析

透過這個模式,可以發現我們原本的 first-helloworld 服務,沒有修改任何一行程式碼,也沒有修改任何的部署檔案,就完成了 istio 模式。

那下方的 istod 則是負責一個 config 設置,以及服務啟動時注入 sidecar ,還有憑證分發。

大家也可以看一下,istio 安裝完後,會在你的 cluster 裡面起一個新的 namepsace

$ kubectl get pods -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE
istiod-95bffc969-5khnq                  1/1     Running   0          5h51m
svclb-istio-ingressgateway-zj6h7        0/5     Pending   0          5h50m
istio-ingressgateway-577b99649b-rm59r   1/1     Running   0          5h50m
istio-egressgateway-7b49cdb77f-h6cht    1/1     Running   0          5h50m

明天我們寫一個小範例來測試,有無 istio 模式下,到底 gRPC 的運作會差異在哪裡。