全方位解讀服務網格(Service Mesh)的背景和概念

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"一直以來“微服務”都是一個熱門的詞彙,在各種技術文章、大會上,關於微服務的討論和主題都很多。對於基於 Dubbo、SpringCloud 技術體系的微服務架構,已經相當成熟並被大家所知曉,但伴隨着互聯網場景的複雜度提升、業務快速變更以及快速響應,如何快速、穩定、高效的應對變幻莫測的業務市場需求,這類技術體系(如:Spring Cloud)的傳統微服務架構就變得力不從心,此時微服務架構再次升級,將","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"服務網格","attrs":{}},{"type":"text","text":"作爲了新一代微服務架構。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本文將從傳統微服務架構出發,爲大家闡述新一代微服務架構--服務網格,它能解決什麼問題,爲用戶帶來什麼,可作爲你對服務網格的認知文章。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"1、背景","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微服務,也稱之爲微服務架構,是一種架構風格,相比單體應用,它將應用程序拆分爲一組服務,並將這些服務組合起來來完成整個複雜的業務功能。下面這些特徵就能高度反映出它的價值所在:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高度可維護和可測試性","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"松耦合","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"獨立部署","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圍繞業務能力進行組織","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"小團隊擁有","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"簡單的回顧完微服務架構的概念,我們一起看看新一代微服務架構是如何誕生的。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.1 基於 Spring Cloud 的微服務體系","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下面這張圖是基於 Spring Cloud 技術體系的微服務架構圖:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/32/32e5f0557da4e8f6ba2cf0f4e9afc24b.png","alt":null,"title":"","style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"針對上圖,從以下兩個方面解讀:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"技術棧:衆所周知,Spring Cloud 相關技術組件很多,雖說大部分都是開箱即用,一旦深度使用,學習成本是很高的,對於初學者(非 Spring Cloud 使用者)來講門檻很高。(太多,而且還都要掌握,太難了!)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":"none"},"content":[{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/3b/3b039018394a07940967e30e6b7cbecf.png","alt":"Spring Cloud組件","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"實現:所有微服務都需要將自身註冊到註冊中心(如:Consul、Eureka 等),來完成服務間的相互調用。每個微服務都必須依賴 Spring Cloud 組件(即:在 pom.xml 中引入),業務邏輯和 Spring Cloud 組件共生在同一個服務中。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"還記得 Spring Cloud 相關組件版本","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"升級","attrs":{}},{"type":"text","text":"時的煩惱麼?爲了使用新版本中的某個特性,或者解決舊版本中存在的漏洞,Spring Cloud 版本升級屢見不鮮,一不留神就會出現版本依賴衝突、啓動不了等等問題,升級完還得安排測試人員測試驗證。技術含量不高,但確實招人煩啊。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"再完美的程序,也避免不了零 bug。上線之後,隨着系統使用場景的多樣性,將逐步會暴露出一些問題,而出現問題就得解決問題,並","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"小心翼翼","attrs":{}},{"type":"text","text":"安排上線,這一系列過程,想必各位肯定深有感觸,各有故事。用“小心翼翼”來形容這一過程決不誇張,因爲一個小小的改動可能會影響到其它,甚至整個系統,這鍋誰都不太想背,","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"能不改打死都不改的原則一直是不願被打破的壁壘","attrs":{}},{"type":"text","text":"。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在傳統行業(如:銀行),由於系統的多樣性、龐大、複雜性,全部加入微服務行列是不現實的,","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"新老系統共存","attrs":{}},{"type":"text","text":"是一種最爲常見的現象。而共存系統間的治理、運維等成了老大難問題。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"面對升級、維護、新老系統共存等這些問題,難道就束手無策了嗎?","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.2 傳統微服務架構面臨的挑戰","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"面對上述暴露出的問題,並在傳統微服務架構下,經過實踐的不斷衝擊,面臨了更多新的挑戰,綜上所述,產生這些問題的原因有以下這幾點:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"過於綁定特定技術棧當面對異構系統時,需要花費大量精力來進行代碼的改造,不同異構系統可能面臨不同的改造。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"代碼侵入度過高開發者往往需要花費大量的精力來考慮如何與框架或 SDK 結合,並在業務中更好的深度融合,對於大部分開發者而言都是一個高曲線的學習過程。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"多語言支持受限微服務提倡不同組件可以使用最適合它的語言開發,但是傳統微服務框架,如 Spring Cloud 則是 Java 的天下,多語言的支持難度很大。這也就導致在面對異構系統對接時的無奈,或選擇退而求其次的方案了。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"老舊系統維護難面對老舊系統,很難做到統一維護、治理、監控等,在過度時期往往需要多個團隊分而管之,維護難度加大。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上述這些問題都是在所難免,我們都知道技術演進來源於實踐中不斷的摸索,將功能抽象、解耦、封裝、服務化。 隨着傳統微服務架構暴露出的這些問題,將迎來新的挑戰,讓大家紛紛尋找其他解決方案。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.3 迎來新一代微服務架構","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"爲了解決傳統微服務面臨的問題,以應對全新的挑戰,微服務架構也進一步演化,最終催生了服務網格(Service Mesh)的出現,迎來了新一代微服務架構,也被稱爲下一代微服務。爲了更好地理解 Service Mesh 的概念和存在的意義,讓我們我們來回顧一下這一演進過程中的四個階段。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/55/5589876c06fe35ce4878833fb97f3ecd.png","alt":null,"title":"","style":[{"key":"width","value":"100%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"耦合階段","attrs":{}},{"type":"text","text":":高度耦合、重複實現、維護困難,在耦合架構設計中體現的最爲突出,單體架構就是典型的代表。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"公共 SDK","attrs":{}},{"type":"text","text":":讓基礎設施功能設計成爲公共 SDK,提高利用率,是解藕最有效的途徑,比如 Spring Cloud 就是類似的方式。但學習成本高、特定語言實現,卻將一部分人攔在了門外。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Sidecar 模式","attrs":{}},{"type":"text","text":":再次深度解藕,不單單功能解藕,更從跨語言、更新發布和運維等方面入手,實現對業務服務的零侵入,更解藕於開發語言和單一技術棧,實現了完全隔離,爲部署、升級帶來了便利,做到了真正的基礎設施層與業務邏輯層的徹底解耦。另一方面,Sidecar 可以更加快速地爲應用服務提供更靈活的擴展,而不需要應用服務的大量改造。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service Mesh","attrs":{}},{"type":"text","text":":把 Sidecar 模式充分應用到一個龐大的微服務架構系統中來,爲每個應用服務配套部署一個 Sidecar 代理,完成服務間複雜的通信,最終就會得到一個的網絡拓撲結構,這就是 Service Mesh,又稱之爲“服務網格“。它從本質上解決了傳統微服務所面臨的問題。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"2、服務網格介紹","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本節從服務網格的定義、核心價值、架構等方面介紹,讓你對它有個充分的認知、瞭解。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.1 服務網格的定義","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"服務網格(Service Mesh),作爲服務間通信的基礎設施層。是輕量級高性能網絡代理,提供安全的、快速的、可靠地服務間通訊,與實際應用部署一起,但對應用透明。應用作爲服務的發起方,只需要用最簡單的方式將請求發送給本地的服務網格代理,然後網格代理會進行後續的操作,如服務發現,負載均衡,最後將請求轉發給目標服務。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"歸納起來,如下圖:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4a/4aa325ae58957269980c5d764e26cfff.png","alt":"Service Mesh定義","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.2 服務網格的核心價值","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"實現業務邏輯和非業務邏輯的分離。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"爲下沉到基礎設施提供可能","attrs":{}},{"type":"text","text":":將微服務通信下沉到基礎設施層,屏蔽了微服務處理各種通信問題的複雜度。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"幫助應用輕量化,專注業務","attrs":{}},{"type":"text","text":":開發者無需關心通信層和服務治理的具體實現,真正像本地調用一樣使用微服務,通信相關的一切工作直接交給 Service Mesh,讓開發者更關注於業務的開發。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"實現應用的雲原生化","attrs":{}},{"type":"text","text":":加速應用上雲,實現雲原生化","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.3 主要功能特性","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那麼服務網格到底能帶來哪些實用的功能呢?","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c6/c61b346274bac09622d149fa7f780bce.png","alt":null,"title":"","style":[{"key":"width","value":"100%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"流量控制","attrs":{}},{"type":"text","text":":爲應用提供智能路由(如,金絲雀發佈、A/B 測試等)、超時重試、熔斷、故障注入、流量鏡像等各種控制能力。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"策略","attrs":{}},{"type":"text","text":":可以爲流量設置配額、黑白名單等策略。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"網絡安全","attrs":{}},{"type":"text","text":":提供服務間訪問控制、 TLS 加密通信。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"可觀測性","attrs":{}},{"type":"text","text":":爲所有通信生成詳細的遙測數據,包括指標數據、日誌、追蹤,提供給應用系統完整的監控能力。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.4 整體架構","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"服務網格整體架構如下圖所示:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/42/424aa7c28c90ebf14283c630523c4699.png","alt":"服務網格整體架構","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"主要核心內容分爲:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"控制平面","attrs":{}},{"type":"text","text":":控制和管理數據平面中的 Sidecar 代理,完成配置分發、服務發現、流量路由、授權鑑權等功能,以達到對數據平面的統一管理。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"數據平面","attrs":{}},{"type":"text","text":":由整個網格內的 Sidecar 代理組成,這些代理以 Sidecar 的形式和應用服務一起部署。這些代理負責協調和控制應用服務之間的所有網絡通信。每一個 Sidecar 會接管進入和離開服務的流量,並配合控制平面完成流量控制等方面的功能。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.5 Istio 框架","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Istio 是由 Google 、IBM 和 Lyft 發起的開源的服務網格框架。該項目在 2017 年推出,截止目前已發佈了 1.10.1 版本。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Istio 提供了一個完整的解決方案,爲整個服務網格提供行爲洞察和操作控制,以滿足微服務應用程序的多樣化需求。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/00/0063ffa0a0ad31919f79191b1fe02b22.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.5.1 Istio 數據平面","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Istio 的數據平面默認使用 Envoy ,是基於 Envoy 新增了一些擴展(即:istio-proxy),C++ 語言編寫。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/1b/1b4348927bacd9cd0c12d97c62e1f209.png","alt":"Istio數據平面","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"主要職責:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"服務發現","attrs":{}},{"type":"text","text":":探測所有可用的上游或下游服務實例。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"健康檢測","attrs":{}},{"type":"text","text":":探測上游或下游服務實例是否健康,是否準備好接收網絡流量。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"流量路由","attrs":{}},{"type":"text","text":":將網絡請求路由到正確的上游或下游服務。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"負載均衡","attrs":{}},{"type":"text","text":":在對上游或下游服務進行請求時,選擇合適的服務實例接收請求,同時負責處理超時、斷路、重試等情況。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"身份驗證和授權","attrs":{}},{"type":"text","text":":在 istio-agent 與 istiod 配合下,對網絡請求進行身份驗證、權限驗證,以決定是否響應以及如何響應,使用 mTLS 或其他機制對鏈路進行加密等。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"鏈路追蹤","attrs":{}},{"type":"text","text":":對於每個請求,生成詳細的統計信息、日誌記錄和分佈式追蹤數據,以便操作人員能夠理解調用路徑並在出現問題時進行調試。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.5.2 Istio 控制平面","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"自 Istio 1.5 版本開始,控制平面由原來分散、獨立部署的三個組件(Pilot、Citadel、Galley)整合爲一個獨立的 istiod,變成了一個單進程、多模塊的組織形態(下圖右圖),極大的降低了原來部署的複雜度。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/19/194c405b4693c3d223025aff88e869e4.png","alt":"Istio控制平面","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Pilot","attrs":{}},{"type":"text","text":":負責 Istio 數據平面的 xDS 配置管理,具體包括服務發現、配置規則發現、xDS 配置下發。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Citadel","attrs":{}},{"type":"text","text":":負責安全證書的管理和發放,實現授權和認證等操作。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Galley","attrs":{}},{"type":"text","text":":負責配置的驗證、提取和處理等功能,將 Istio 和底層平臺(如,Kubernetes)進行解耦。","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其中,Citadel、Galley 組件逐步在弱化,在 Istio 版本迭代中,已經基本看不見它們的蹤跡了。(已經不斷整合在其它組件中)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接下來,着重看看 Pilot 組件。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Pilot 是 Istio 中的核心組件,用於管理和配置部署在特定 Istio 服務網格中的所有 Sidecar 代理實例。它管理 Sidecar 代理之間的路由流量規則,並配置故障恢復功能,如超時、重試和熔斷等。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/3d/3d2c5eb1b43c261627199b2997f22336.png","alt":"Pilot組件","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"關鍵模塊:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"抽象模型(Abstract model)","attrs":{}},{"type":"text","text":":爲了實現對不同服務註冊中心 (如,Kubernetes、Consul) 的支持,完成對不同輸入來源數據的抽象,形成統一的存儲格式。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"平臺適配器 (Platform adapters)","attrs":{}},{"type":"text","text":":藉助平臺適配器 Pilot 實現服務註冊中心數據到抽象模型之間的數據轉換。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"xDS API","attrs":{}},{"type":"text","text":":是源於 Envoy 項目的標準數據平面 API, 將服務信息和流量規則下發到數據平面的 Sidecar。通過採用該標準 API, Istio 將控制平面和數據平面進行了解耦,爲多種數據平面 Sidecar 實現提供了可能性,如:螞蟻金服開源的 Golang 版本的 MOSN。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"用戶 API(User API)","attrs":{}},{"type":"text","text":":提供了面向業務的高層抽象,可以被運維人員理解和使用。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"3、總結","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"讓我們一起回顧下,Spring Cloud 微服務架構和 Service Mesh 微服務架構:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f4/f43a423d79fd84803a1670efab476a6b.png","alt":null,"title":"","style":[{"key":"width","value":"100%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"爲了解決微服務框架的侵入性問題,我們引入服務網格。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"參考資料:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://microservices.io/","title":"","type":null},"content":[{"type":"text","text":"https://microservices.io/","attrs":{}}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://xcbeyond.cn/blog/servicemesh/migration-from-springcloud-to-servicemesh/","title":"","type":null},"content":[{"type":"text","text":"構建基於 Spring Cloud 向 Service Mesh 框架遷移的解決方案及思路","attrs":{}}]}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/8e/8e59a507f380dcfe441a12686863788b.jpeg?x-oss-process=image/resize,p_80/auto-orient,1","alt":null,"title":"","style":[{"key":"width","value":"100%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章