構建基於Spring Cloud向Service Mesh框架遷移的解決方案及思路

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作爲新一代微服務架構體系,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 技術有效地解決了 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 微服務架構和服務治理過程中的痛點問題,一經推出便引起了很大的反響。近一年來,伴隨着雲原生的熱火朝天,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 被推向了巔峯,從陌生走向大家的視界,甚至一些初創企業都想從中獲得第一桶金。對於初創企業或全新產品,選擇 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 變得相對輕鬆很多,畢竟不存在遷移的問題。但對於大部分企業或成熟的產品體系,這樣大的架構轉型就變得很難以實施,需要多加權衡利弊,面對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"SDK","attrs":{}}],"attrs":{}},{"type":"text","text":" 的傳統微服務框架(例如,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Dubbo","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":")進行服務治理,而隨着 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的普及,越來越多的企業開始佈局自己的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架體系,但多數企業剛開始不會激進地將所有業務遷移至 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Serivice Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":",畢竟這樣風險太大、收益太慢。像 Java 技術棧應用依然保留原框架,而非 Java 技術棧應用採用 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架,不同開發語言可以用不同的技術框架,但業務不能被框架割裂,那麼在這兩種架構體系下應用服務如何互聯互通?微服務如何統一治理?傳統微服務又如何平滑遷移至 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 向 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架遷移過程中的諸多問題展開討論,儘可能提供一套完善的解決方案和遷移思路,供大家參考。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"1、背景","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微服務是近些年來軟件架構中的熱名詞,也是一個很大的概念,不同人對它的理解都各不相同,甚至在早期微服務架構中出現了一批四不像的微服務架構產品,有人把單純引入","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Boot","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":"框架也叫做微服務架構,卻只是將它作爲服務的Web容器而已。","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":"隨着微服務的火熱,越來越多的團隊開始實踐,將微服務紛紛落地,並投入生產。但隨着微服務規模的不斷壯大,每增加一個微服務,就可能會增加一些依賴的基礎設施和第三方的配置,比如Kafka實例等,相應CI/CD的配置也會增加或調整。 同時隨着微服務數量增多、業務複雜性的提升及需求的多樣性等(如,對接第三方異構系統等),服務間通信的錯綜複雜,一步步地將微服務變得更加臃腫,服務治理也是難上加難,而這些問題在單體架構中很容易解決。爲此,有人開始懷疑當初微服務化是否是明智之選,甚至考慮迴歸到傳統單體應用。","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":"正如下圖所示,PPT 中的微服務總是美好的,但現實中的微服務卻是一團糟糕,想甩甩不掉,越看越糟心。難道就沒有辦法了麼?","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/8d/8d0910e8dc29a2fce884857c29d9e183.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":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"1.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":"codeinline","content":[{"type":"text","text":"SDK","attrs":{}}],"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","text":"多語言支持。微服務提倡不同組件可以使用最適合它的語言開發,但是在 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架下就是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":2},"content":[{"type":"text","text":"1.2 迎來新一代微服務架構","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"爲了解決傳統微服務面臨的問題,以應對全新的挑戰,微服務架構也進一步演化,最終催生了","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的出現,迎來了新一代微服務架構,也被稱爲下一代微服務。爲了更好地理解 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的概念和存在的意義,我們來回顧一下這一演進過程。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.2.1 耦合階段","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在微服務架構中,服務發現、熔斷、治理等能力是微服務架構重要的組成部分。微服務化之後,服務更加的分散,複雜度變得更高,起初開發者將諸如熔斷、超時等功能和業務代碼封裝在一起,使服務具備了網絡控制能力,如下圖所示。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/d6/d66a36bbbbd1b5c4f193be5159963931.png","alt":null,"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},"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":"基礎設施功能(如,服務發現,j負載均衡、熔斷等)和業務邏輯耦合。","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":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.2.2 公共庫SDK","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"基於上面存在的問題,很容易會想到將基礎設施功能設計爲一個公共庫SDK,讓服務的業務邏輯與這些功能減低耦合度,提高重複利用率,更重要的是開發者只需要關注公共庫SDK的依賴及使用,而不必實現這些功能,從而更加專注於業務邏輯的開發,比如 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架是類似的方式。如下圖所示:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4f/4f075ca437f11f5252e69fb98022da58.png","alt":null,"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","text":"這些公共庫SDK存在較爲陡峭的學習成本,需要耗費開發人員一定的時間和人力與現有系統集成,甚至需要考慮修改現有代碼進行整合。","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":"公共庫SDK的管理和維護依然需要耗費開發者的大量精力,並需專門人員來進行管理維護。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.2.3 Sidecar模式","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"有了上面公共庫SDK的啓發,加上跨語言問題、更新後的發佈和維護等問題,人們發現更好的解決方案是把它作爲一個代理,服務通過這個透明的代理完成所有流量的控制。","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":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 代理模式,也被翻譯爲邊車代理,它作爲與其他服務通信的橋樑,爲服務提供額外的網絡特性,並與服務獨立部署,對服務零侵入,更不會受限於服務的開發語言和技術棧的限制,如下圖所示。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c4/c4c2391fa54fbd5dc2a31081d14b8756.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","text":"以 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 模式進行通信代理,實現了基礎實施層與業務邏輯的完全隔離,在部署、升級時帶來了便利,做到了真正的基礎設施層與業務邏輯層的徹底解耦。另一方面,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 可以更加快速地爲應用服務提供更靈活的擴展,而不需要應用服務的改造。","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"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":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"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","text":"服務治理。","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 可以完全攔截服務進出的流量,並對其進行相應的調用鏈跟蹤、熔斷、降級、日誌監控等操作,將服務治理功能集中在 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"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","text":"集中管控。整個微服務架構體系下的所有服務完全可以通過 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"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.2.4 Service Mesh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"把 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 模式充分應用於一個龐大的微服務架構系統,爲每個應用服務配套部署一個 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 代理,完成服務間複雜的通信,最終就會得到一個如下所示的網絡拓撲結構,這就是 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":",又稱之爲“服務網格“。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/d3/d3f4c0a2cf62fe19b1970cf7e5da3589.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","text":"至此,迎來了新一代微服務架構——","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":",它徹底解決了傳統微服務架構所面臨的問題。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"1.3 什麼是Service Mesh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在開始進入主題之前,我認爲有必要再對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 進行統一的闡述,這樣將有助於理解它,更加便於閱讀接下來的內容。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.3.1 Service Mesh介紹","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"目的是解決系統架構微服務化後的服務間通信和治理問題。","attrs":{}},{"type":"text","text":"服務網格由","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":"節點組成,這個模式的精髓在於實現了數據面(業務邏輯)和控制面的解耦。具體到微服務架構中,即給每一個微服務實例同步部署一個","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":"。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/e6/e66a1203d091e0a93dab3008d2c49123.png","alt":null,"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},"content":[{"type":"text","text":"在","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"部署網絡結構圖中,綠色方塊爲應用服務,藍色方塊爲 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"SideCar","attrs":{}}],"attrs":{}},{"type":"text","text":",應用服務之間通過","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":"進行通信,整個服務通信形成圖中的藍色網絡連線,圖中所有藍色部分就形成了","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"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":{}}]}]}],"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":"Service Mesh的出現解決了傳統微服務框架中的痛點,使得開發人員專注於業務本身,同時,將服務通信及相關管控功能從業務中分離到基礎設施層。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.3.2 Service Mesh的功能","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那麼 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"上實現安全機制(如","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"TLS","attrs":{}}],"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","text":"多語言支持。作爲獨立運行且對業務透明的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 代理,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 主要體現在以下4個方面:","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":"codeinline","content":[{"type":"text","text":"TLS","attrs":{}}],"attrs":{}},{"type":"text","text":" 加密通信。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.3.3 Service Mesh解決什麼問題","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從上述","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"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":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service Mesh","attrs":{}}],"attrs":{}},{"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":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service Mesh","attrs":{}}],"attrs":{}},{"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","text":"請求的可靠傳遞是","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","text":"輕量級網絡代理是","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","text":"對應用程序透明是","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"主要解決用戶如下3個維度的痛點需求:","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":"listitem","attrs":{"listStyle":"none"},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過將微服務通信下沉到基礎設施層,屏蔽了微服務處理各種通信問題的複雜度,形成微服務之間的抽象協議層。開發者無需關心通信層的具體實現,也無需關注","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"RPC","attrs":{}}],"attrs":{}},{"type":"text","text":"通信(包含服務發現、負載均衡、流量調度、流量降級、監控統計等)的一切細節,真正像本地調用一樣使用微服務,通信相關的一起工作直接交給","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"listitem","attrs":{"listStyle":"none"},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"功能上,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"並沒有提供任何新的特性和能力,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"提供的所有通信和服務治理能力在","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"之前的技術中均能找到,比如","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":"就實現了完善的微服務","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"RPC","attrs":{}}],"attrs":{}},{"type":"text","text":"通信和服務治理支持。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":"none"},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"改變的是通信和服務治理能力提供的方式,通過將這些能力實現從各語言業務實現中解耦,下沉到基礎設施層面,以一種更加通用和標準化的方式提供,屏蔽不同語言、不同平臺的差異性","attrs":{}},{"type":"text","text":",有利於通信和服務治理能力的迭代和創新,使得業務實現更加方便。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":"none"},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"避免了多語言服務治理上的重複建設,通過","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"微服務治理層面","attrs":{}},{"type":"text","text":",","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"是標準化、體系化、無侵入的分佈式治理平臺。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"標準化方面","attrs":{}},{"type":"text","text":",","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":"成爲所有微服務流量通信的約束標準,同時","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":"的數據平臺和控制平面也通過標準協議進行交互。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"體系化方面","attrs":{}},{"type":"text","text":",從全局考慮,提供多維度立體的微服務可觀測能力(","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Metric","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Trace","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Logging","attrs":{}}],"attrs":{}},{"type":"text","text":"),並提供體系化的服務治理能力,如限流、熔斷、安全、灰度等。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":"none"},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過標準化,帶來一致的服務治理體驗,減少多業務之間由於服務治理標準不一致帶來的溝通和轉換成本,提升全局服務治理的效率。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1.3.4 Service Mesh框架選型","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下面對針對目前市面上常見的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架進行的比較彙總,見下表所示:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/80/80a41f575dc464fe928b68b0ba9cc493.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":"image","attrs":{"src":"https://static001.geekbang.org/infoq/74/742d806a4ca69d491d964951ad1290e3.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},"content":[{"type":"text","text":"上述任何一個 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架都能夠滿足您的基本需求。到⽬前爲⽌,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 具有這幾個服務⽹格框架中最多的功能和靈活性,靈活性意味着複雜性,因此需要團隊更爲充⾜的準備。如果只想使⽤基本的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 治理功能,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Linkerd","attrs":{}}],"attrs":{}},{"type":"text","text":" 可能是最佳選擇。如果您想⽀持同時包含 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"VM","attrs":{}}],"attrs":{}},{"type":"text","text":" 的異構環境,並且不需要 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 的複雜性,那麼 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Consul","attrs":{}}],"attrs":{}},{"type":"text","text":" 可能是您的最佳選擇,⽬前 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 也提供了同時包含 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"VM","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 社區正在快速迭代以應對各種場景,併力爭作爲 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的標杆,本文以選取 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架作爲最終遷移框架。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"1.4 框架遷移迫在眉睫","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"爲了更好的佔領市場,滿足更多業務場景的需求,傳統微服務架構(如,基於 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架的微服務架構)面臨了衆多新的挑戰,而 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架的微服務向 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架遷移必將迫在眉睫,是推翻重來,還是循序遷移?","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"2、Service Mesh遷移方案","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於還未涉足 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的企業或產品,其傳統微服務架構如若是採用 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架構建,此時向","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架遷移該如何做呢?需要綜合考慮哪些因素?是否有依可據呢?接下來,我們就構建基於","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 向 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架遷移提供一些建議方案和思路,供大家參考。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"2.1 遷移場景","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"傳統微服務框架,我們以最爲典型的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"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":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架開發。(服務中包含業務邏輯和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"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","text":"開發語言是以Java爲主。(存在跨語言的限制)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"註冊中心採用的是 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Consul","attrs":{}}],"attrs":{}},{"type":"text","text":" 或 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Eureka","attrs":{}}],"attrs":{}},{"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":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 已經成爲 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 事實上的標準,更是新一代微服務架構發展的趨勢,因此公司希望嘗試遷移到 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架,最終形成下圖右邊部分。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/e6/e6f125bd6401a3e82049834e3a6722e9.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":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"2.2 遷移路徑","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"面對上述遷移場景,確定要引入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 時,就要徹底搞清楚 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","marks":[{"type":"strong","attrs":{}}],"text":"首先","attrs":{}},{"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"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","marks":[{"type":"strong","attrs":{}}],"text":"其次","attrs":{}},{"type":"text","text":",完成 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 微服務平臺的搭建。當前所處階段是否已經支持容器化和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":"。如果當前業務已經運行在 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 之上,則 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的遷移將會非常順暢;如果當前業務沒有運行在","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":"上,因 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 當前典型的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 有着過度依賴,所以可能就無法直接從 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 遷移到 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架,即使定製修改 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 以接觸對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"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","marks":[{"type":"strong","attrs":{}}],"text":"路徑一:非 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":" 環境下,先接入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Sidecar","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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的迫切需求,可採取先接入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":",來滿足當前業務的痛點需求。在引入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 時,要注意其未來的演進方向,考慮後續可能繼續向 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 遷移,一旦時機成熟並引入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 容器化後,則能夠順利由 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 的方式直接演進到 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 當前典型的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架在非 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 下沒有很好的支持(據說未來會完全脫離對","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 的依賴),對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 進行定製化修改以支持非 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 環境下引入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":",數據平面可使用 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Envoy","attrs":{}}],"attrs":{}},{"type":"text","text":",控制平面可根據 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"XDS","attrs":{}}],"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","marks":[{"type":"strong","attrs":{}}],"text":"路徑二:先進行 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":" 容器化改造,再接入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Service Mesh","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":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 容器化改造,再接入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","marks":[{"type":"strong","attrs":{}}],"text":"最後, ","attrs":{}},{"type":"text","text":" 基於構建的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架,將業務應用逐步遷移到 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 上來。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"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":"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 遷移對業務的影響,減少業務的遷移阻力,遷移初期必須確保業務完全透明且不需要過多的變更和修改。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":"none"},"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","marks":[{"type":"strong","attrs":{}}],"text":"兼容性:","attrs":{}},{"type":"text","text":" 在遷移階段,必然會存在兩種模式( ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架)並存,在遷移過程中需要充分考慮兩者的兼容性,使得遷移前後網絡打通,至少能夠滿足未遷移和已遷移部分能夠通信。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"2.4 遷移方案","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 向 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架遷移,大體上分爲四個步驟:","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 架構分析、容器化改造、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 微服務平臺搭建和應用遷移。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.4.1 Spring Cloud架構分析","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 架構分析的目的在於重新瞭解我們當前微服務架構下的所有功能,便於在向 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 遷移時做準備,考慮哪些功能需要遷移,哪些不需要遷移,哪些需要改造等。我們先看一下基於 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 完整構建的微服務架構解決方案,如下圖所示。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/8c/8c778abbd2880c8a8a1a2f5a4ba8ee86.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","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":"應用服務:覆蓋整個業務服務,包括業務邏輯實現、框架SDK及外部組件依賴交互等。","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":"CI&CD:持續集成、持續部署。","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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" (以 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 爲例)能夠去做的?經過分析得知,可以替換的組件包括網關(","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Gateway","attrs":{}}],"attrs":{}},{"type":"text","text":" 或者 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Zuul","attrs":{}}],"attrs":{}},{"type":"text","text":",由 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Ingress gateway","attrs":{}}],"attrs":{}},{"type":"text","text":" 或者 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"egress","attrs":{}}],"attrs":{}},{"type":"text","text":" 替換),熔斷器(","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"hystrix","attrs":{}}],"attrs":{}},{"type":"text","text":",由 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 替換),註冊中心(","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Eureka","attrs":{}}],"attrs":{}},{"type":"text","text":" 及 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Eureka client","attrs":{}}],"attrs":{}},{"type":"text","text":",由 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Polit","attrs":{}}],"attrs":{}},{"type":"text","text":",","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 替換),負責均衡( ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Ribbon","attrs":{}}],"attrs":{}},{"type":"text","text":",由 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 中的哪些內容可以由 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 處理,哪些內容可以繼續沿用。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.4.2 容器化改造","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"容器化改造,主要針對目前還未引入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"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":"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","text":"更省:極大的資源利用效率, 最大限度榨取和共享物理資源,多項目更能體現出容器化多優勢,節約部署 IT 成本。","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":"靈活:監控底層 node 節點健康狀態,靈活調度至最優節點部署。","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","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","text":"掌握 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Docker","attrs":{}}],"attrs":{}},{"type":"text","text":" 技術:開發人員需熟悉 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Docker","attrs":{}}],"attrs":{}},{"type":"text","text":" 容器化技術,熟練編寫 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Dockerfile","attrs":{}}],"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","text":"掌握 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 編排系統:熟悉 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 容器化編排系統, 熟悉各組件資源清單編寫、高可用、 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"RBAC","attrs":{}}],"attrs":{}},{"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":"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":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 搭建的所有服務實現容器化構建,實現 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Docker","attrs":{}}],"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","text":"容器化管理:基於 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 進行服務容器的管理。","attrs":{}}]}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.4.2.1 容器化構建","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"容器化構建需藉助編寫的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Dockerfile","attrs":{}}],"attrs":{}},{"type":"text","text":" 文件,並通過 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Jenkins","attrs":{}}],"attrs":{}},{"type":"text","text":" 自動化完成對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Docker","attrs":{}}],"attrs":{}},{"type":"text","text":" 鏡像的製作。這裏以一個簡單的","attrs":{}},{"type":"link","attrs":{"href":"https://github.com/xcbeyond/springCloudLearning/tree/master/serviceProvider","title":"","type":null},"content":[{"type":"text","text":"serviceProvider服務","attrs":{}}]},{"type":"text","text":"(基於 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"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":"(1)創建 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Dockerfile","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"serviceProvider/src/main/docker","attrs":{}}],"attrs":{}},{"type":"text","text":"目錄下創建一個 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Dockerfile","attrs":{}}],"attrs":{}},{"type":"text","text":" 文件,內容如下:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"dockerfile"},"content":[{"type":"text","text":"FROM java:8\nRUN mkdir /microservice\nWORKDIR /microservice\nADD /service-provider-1.0.jar /microservice/\nEXPOSE 8001\nENTRYPOINT [\"java\", \"-Djava.security.egd=file:/dev/./urandom\", \"-jar\", \"/microservice/service-provider-1.0.jar\"]\n","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":"(2)配置pom ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"docker-maven-plugin","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"serviceProvider","attrs":{}}],"attrs":{}},{"type":"text","text":" 的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"pom.xml","attrs":{}}],"attrs":{}},{"type":"text","text":" 中配置 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"build","attrs":{}}],"attrs":{}},{"type":"text","text":" 部分,內容如下:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"\n \n install\n \n service-provider-${project.version}\n \n \n \n org.springframework.boot\n spring-boot-maven-plugin\n \n \n \n \n com.spotify\n docker-maven-plugin\n 0.4.13\n \n \n install\n \n build\n tag\n \n \n \n \n \n http://dockerip:2375\n ${project.build.finalName}\n java\n \n \n [\"java\", \"-Djava.security.egd=file:/dev/./urandom\", \"-jar\", \"/${project.build.finalName}.jar\"]\n \n \n \n /\n ${project.build.directory}\n ${project.build.finalName}.jar\n \n \n ${docker.image.prefix}/${project.build.finalName}\n ${docker.image.prefix}/${project.build.finalName}:${docker.tag}\n true\n \n false\n \n \n \n \n","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":"(3)打包。","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":"codeinline","content":[{"type":"text","text":"mvn package","attrs":{}}],"attrs":{}},{"type":"text","text":" 的時候,會根據 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"pom.xml","attrs":{}}],"attrs":{}},{"type":"text","text":" 中 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"build","attrs":{}}],"attrs":{}},{"type":"text","text":" 配置自動打包 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Docker","attrs":{}}],"attrs":{}},{"type":"text","text":" 鏡像,並推送到Docker服務器上。","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":4},"content":[{"type":"text","text":"2.4.2.2 容器化管理","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"容器化管理實際上就是將服務容器通過 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":"編排系統,完成對服務部署、管理等,需要對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 有一定的瞭解,會熟練使用它,看參考之前寫的","attrs":{}},{"type":"link","attrs":{"href":"https://xie.infoq.cn/tag/7282","title":"","type":null},"content":[{"type":"text","text":"”Kubernetes從入門到精通“","attrs":{}}]},{"type":"text","text":"系列文章。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.4.3 Service Mesh 微服務平臺搭建","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 我們選取 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架,關於選型方案可參考之前文章:","attrs":{}},{"type":"link","attrs":{"href":"https://xie.infoq.cn/article/fa7e10501c948f177d9f52fe0","title":"","type":null},"content":[{"type":"text","text":"Service Mesh 框架選型對比分析:Linkerd、Envoy、Istio、Conduit","attrs":{}}]},{"type":"text","text":"。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.4.3.1 istio基礎框架搭建","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"基於 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架搭建 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"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":{}}]}]}],"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":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 架構圖如下:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/bd/bd3d4c7b4da2981fa96e4a758a556662.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","text":"至此,一個 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 基礎框架搭建完成,能夠提供 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的所有能力。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.4.3.2 istio擴展和定製","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在遷移路徑中已經提及過,對於非 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 環境,建議先引入 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":",並採取 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 對虛擬機的支持方案,在虛擬機環境下運行。但如果有多平臺支持的場景,比如既有 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 環境,又有虛擬機環境,需對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 進行定製化改造,去掉對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 的強依賴和耦合,增加對其他平臺的支持。(對於多平臺的支持,目前","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 還未支持,但從 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"istio","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"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":"(1)API資源管理層對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes API Server","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 依賴最大的地方。","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 對核心資源的管理,是以 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes CRD","attrs":{}}],"attrs":{}},{"type":"text","text":" 爲基礎,並使用 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"kubectl","attrs":{}}],"attrs":{}},{"type":"text","text":" 作爲命令行操作入口,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"kubectl","attrs":{}}],"attrs":{}},{"type":"text","text":" 調用 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"API Server","attrs":{}}],"attrs":{}},{"type":"text","text":",將資源存放在 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"etcd","attrs":{}}],"attrs":{}},{"type":"text","text":" 中,並通過 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes CRD","attrs":{}}],"attrs":{}},{"type":"text","text":" 機制觸發資源變更事件通知,通知關心 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 的綁定,則需要自行實現這一套API管理方式,並且做到平臺無關。","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":"(2)通信訪問層面對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"kube DNS","attrs":{}}],"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":"codeinline","content":[{"type":"text","text":"DNS","attrs":{}}],"attrs":{}},{"type":"text","text":" 獲取服務的虛擬IP地址,","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"DNS","attrs":{}}],"attrs":{}},{"type":"text","text":" 實現沿用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes DNS","attrs":{}}],"attrs":{}},{"type":"text","text":" 方案,基於 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"DNS","attrs":{}}],"attrs":{}},{"type":"text","text":" 通過服務名實現直接訪問。因此需要在 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"DNS","attrs":{}}],"attrs":{}},{"type":"text","text":" 方案層面接觸和","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 的耦合,並使用平臺無關的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"DNS","attrs":{}}],"attrs":{}},{"type":"text","text":" 解決方案。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.4.3.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":"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":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","text":"新上的業務或者存量的非關鍵業務可以做爲試點,先容器化、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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","text":"對於未遷移的存量應用和遷移完成的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"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":"面對上述這些真實而又合理的訴求,在進行Service Me還是微服務平臺搭建時,必然會存在兩種框架並存的場景,如下圖所示,左邊是未遷移的存量服務,右邊是容器化並Service Mesh化的試點服務,但這種模式服務間卻是互不相同,且無法統一治理。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/72/720fa432aa48773fb92967cdb0deb9eb.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","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":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同樣,我們可以針對 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 的控制平面做些文章,通過自定義控制插件(","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"WASM","attrs":{}}],"attrs":{}},{"type":"text","text":")將 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架中原有註冊中心的功能納入進來,由控制平面提供原有服務註冊與發現的能力,並結合 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 中入口網關 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Ingress","attrs":{}}],"attrs":{}},{"type":"text","text":" 和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"ServiceEntry","attrs":{}}],"attrs":{}},{"type":"text","text":" 資源配置,以實現服務間互通,統一治理,整個實現邏輯架構如下圖所示。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4c/4cd72c08ec0320f062f5c2cea61b4999.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","text":"至此,實現了基於","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 兩種框架的並存。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2.4.4 應用遷移","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"到這裏,我們已經完成了 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 微服務平臺的搭建,那在這樣的平臺上我們如何將應用 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 應用逐步向 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":" 遷移呢?","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.4.4.1 去除重疊功能","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們先來看一下 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架與 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 框架的功能重疊情況:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/87/875022d547af7b72880bfceb1cdf06c5.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","text":"從上表功能情況,存在大量重疊功能,需將","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 與 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 中重疊功能去除,缺失功能保留,理論上可輕鬆去重。對於 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Spring Cloud","attrs":{}}],"attrs":{}},{"type":"text","text":" 而言,這些重疊功能大部分只需去除 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"pom.xml","attrs":{}}],"attrs":{}},{"type":"text","text":" 中依賴包、相關配置及代碼中註解即可輕鬆完成,剩餘一個相對乾淨的應用。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.4.4.2 應用注入","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"應用注入是指在將應用服務部署到網格時,將Sidecar注入到應用服務中去,以實現網格的代理。","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":"Sidecar注入,分爲手動注入和自動注入:","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":"codeinline","content":[{"type":"text","text":"istioctl kube-inject","attrs":{}}],"attrs":{}},{"type":"text","text":" 來重新構造應用的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"CRD yaml","attrs":{}}],"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","text":"自動注入:通過 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"mutable webhook","attrs":{}}],"attrs":{}},{"type":"text","text":" 回調 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"istio-sidecar-injector","attrs":{}}],"attrs":{}},{"type":"text","text":" 服務來重新構造應用的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"CRD yaml","attrs":{}}],"attrs":{}},{"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":"image","attrs":{"src":"https://static001.geekbang.org/infoq/60/607fbc7ac200cd6ed5a49b49b0d9a07f.jpeg","alt":null,"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":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 注入的本質是將運行 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 所需要的鏡像地址、啓動參數、所連接的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Istio","attrs":{}}],"attrs":{}},{"type":"text","text":" 集羣(","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Pilot","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Citadel","attrs":{}}],"attrs":{}},{"type":"text","text":"、","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Galley","attrs":{}}],"attrs":{}},{"type":"text","text":")及配置信息填充到注入模版,並添加到應用的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"CRD yaml","attrs":{}}],"attrs":{}},{"type":"text","text":" 中,最終通過 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes","attrs":{}}],"attrs":{}},{"type":"text","text":" 持久化資源並拉起應用和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Sidecar","attrs":{}}],"attrs":{}},{"type":"text","text":" 的 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"POD","attrs":{}}],"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":"此時,應用已成功遷移部署到Service Mesh中了。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"3、總結","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這篇文章從傳統微服務架構開始一步步介紹到 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"attrs":{}},{"type":"text","text":",並提出了傳統微服務架構面臨的挑戰,針對現狀,如何能夠更好的滿足市場需求,而不被市場淘汰,介紹了傳統微服務如何平滑遷移至 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"Service Mesh","attrs":{}}],"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":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"參考資料:","attrs":{}}]},{"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://istio.io/latest/docs/concepts/what-is-istio/","title":"","type":null},"content":[{"type":"text","text":"https://istio.io/latest/docs/concepts/what-is-istio/","attrs":{}}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"劉俊海 著《Service Mesh微服務架構設計》","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s/y9PZLgHhVcdsMuTzAyIMsQ","title":"","type":null},"content":[{"type":"text","text":"https://mp.weixin.qq.com/s/y9PZLgHhVcdsMuTzAyIMsQ","attrs":{}}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.servicemesher.com/blog/service-mesh-rebuild-microservice-market/","title":"","type":null},"content":[{"type":"text","text":"https://www.servicemesher.com/blog/service-mesh-rebuild-microservice-market/","attrs":{}}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s/-MszFJORuDJKf3V5ndyimw","title":"","type":null},"content":[{"type":"text","text":"https://mp.weixin.qq.com/s/-MszFJORuDJKf3V5ndyimw","attrs":{}}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":6,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.servicemesher.com/blog/netease-yeation-service-mesh/","title":"","type":null},"content":[{"type":"text","text":"https://www.servicemesher.com/blog/netease-yeation-service-mesh/","attrs":{}}]}]}]}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章