邊緣上的容器化

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"像 Docker 這樣的應用容器是雲原生增長的主要推動力。不過,儘管雲原生開發範式已被證明是非常流行的,但是由於應用容器需要大量的計算資源,將雲原生基礎設施擴展到大型數據中心之外就變得困難了。"}]},{"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":"比如,Docker 不支持實時操作系統(real-time operating systems,RTOS),而只支持 POSIX 系統。在像智能工廠和智能汽車這樣的邊緣網絡和設備上,行業生態系統和供應商網絡決定了應用必須從多個獨立的供應商“組合”。舉例來說,一個典型的電動汽車有 100 多個廠商爲汽車的不同部分編寫軟件組件。爲汽車 OEM 提供一個安全、高效、實時的運行環境,對各供應商和廠商進行軟件集成具有重要意義。現在已經有了一些在邊緣實時操作系統上支持應用容器的嘗試。"}]},{"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":"VxWorks 是商用實時操作系統,應用於飛機和航天器等關鍵任務系統。"},{"type":"link","attrs":{"href":"https:\/\/blogs.windriver.com\/wind_river_blog\/2021\/04\/rtos-containers-for-the-intelligent-edge\/","title":"","type":null},"content":[{"type":"text","text":"VxWorks 容器"}]},{"type":"text","text":"是最近的一項倡議(2021 年),它支持在 VxWorks 實時操作系統上遵循 OCI 的輕量級容器。但是,Docker 方法並不適用於邊緣的實時操作系統。"}]},{"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":"從根本上說,Docker 並不具有實時性,因爲它假定了很多底層操作系統服務的可用性。對於實時操作系統來說,一個更好的運行時方式是高級字節碼虛擬機。這樣的虛擬機比 Docker 更輕、更快。它們提供了基於功能的安全沙箱,幾乎不考慮底層操作系統服務,同時,在前端支持多種編程語言。WebAssembly 有着廣泛的行業支持和輕量級設計,這似乎就是複雜邊緣應用的完美虛擬機運行時間。"}]},{"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":"WebAssembly 的另一個有趣之處在於 WebAssembly 程序的正確性通常可以與 seL4 本身一樣得到正式驗證。因此,它適用於關鍵人物系統,如汽車操作系統。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"WasmEdge 和 seL4"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/seL4.systems\/","title":"","type":null},"content":[{"type":"text","text":"seL4"}]},{"type":"text","text":" 操作系統是一種經過正式驗證的高安全性和實時性的微內核操作系統。它目前越來越多地用於自動駕駛汽車和無人機,在這些地方,安全性和實時性非常重要。seL4 操作系統是一種不遵循 POSIX 的微內核,因此對於運行類似 Docker 的容器尤其具有挑戰性。而 WebAssembly 則可以對操作系統進行很大程度的抽象化,並向開發者提供一套統一的編程語言和 SDK。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/github.com\/WasmEdge\/WasmEdge","title":"","type":null},"content":[{"type":"text","text":"WasmEdge Runtime"}]},{"type":"text","text":" 是 CNCF 託管的高性能的開源 WebAssembly 運行時。將其作爲 "},{"type":"link","attrs":{"href":"https:\/\/www.infoq.com\/articles\/webassembly-dapr-wasmedge\/","title":"","type":null},"content":[{"type":"text","text":"微服務"}]},{"type":"text","text":"、"},{"type":"link","attrs":{"href":"https:\/\/www.cncf.io\/blog\/2021\/08\/25\/webassembly-serverless-functions-in-aws-lambda\/","title":"","type":null},"content":[{"type":"text","text":"無服務器"}]},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/vercel-wasmedge-webassembly-rust\/","title":"","type":null},"content":[{"type":"text","text":"函數"}]},{"type":"text","text":"和"},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/extend-golang-app-with-webassembly-rust\/","title":"","type":null},"content":[{"type":"text","text":"插件"}]},{"type":"text","text":"的運行時使用在雲原生基礎設施中。除標準的 WebAssembly 規範外,WasmEdge 支持擴展 API,這些 API 與雲原生"},{"type":"link","attrs":{"href":"https:\/\/github.com\/WasmEdge\/WasmEdge\/blob\/master\/docs\/use_cases.md","title":"","type":null},"content":[{"type":"text","text":"用例"}]},{"type":"text","text":"相關,比如"},{"type":"link","attrs":{"href":"https:\/\/github.com\/second-state\/wasmedge_wasi_socket","title":"","type":null},"content":[{"type":"text","text":"網絡套接字"}]},{"type":"text","text":"、"},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/wasi-tensorflow\/","title":"","type":null},"content":[{"type":"text","text":"基於 TensorFlow 的推理"}]},{"type":"text","text":"、數據庫存儲等等。WasmEdge 支持 Rust 和 "},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/run-javascript-in-webassembly-with-wasmedge\/","title":"","type":null},"content":[{"type":"text","text":"JavaScript"}]},{"type":"text","text":" 作爲前端語言,可以作爲插件或者嵌入式函數嵌入到 "},{"type":"link","attrs":{"href":"https:\/\/github.com\/WasmEdge\/WasmEdge\/tree\/master\/bindings\/rust","title":"","type":null},"content":[{"type":"text","text":"Rust"}]},{"type":"text","text":"、"},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/extend-golang-app-with-webassembly-rust\/","title":"","type":null},"content":[{"type":"text","text":"Go"}]},{"type":"text","text":"、Python 和 "},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/getting-started-with-rust-function\/","title":"","type":null},"content":[{"type":"text","text":"Node.js"}]},{"type":"text","text":" 主機應用中。"}]},{"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":"與“邊緣容器”用例最相關的是,WasmEdge 是一種"},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/manage-webassembly-apps-in-wasmedge-using-docker-tools\/","title":"","type":null},"content":[{"type":"text","text":"兼容 OCI 的運行時"}]},{"type":"text","text":",Docker 工具和 Kubernetes 可以對其進行管理和協調。在這項工作中,我們構建了一個 WebAssembly 管理代理,用於 seL4 和 WasmEdge。可以讓 WebAssembly 字節碼應用在 seL4 實時操作系統上部署和執行。"}]},{"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":"官方說法是,seL4 只支持用 c\/c + + 編寫的應用程序。有了 WasmEdge Runtime,開發者現在可以使用任何 WebAssembly 語言來編寫 seL4 實時操作系統應用程序,包括 Rust、 Swift、 AssemblyScript 和 "},{"type":"link","attrs":{"href":"https:\/\/www.secondstate.io\/articles\/run-javascript-in-webassembly-with-wasmedge\/","title":"","type":null},"content":[{"type":"text","text":"JavaScript"}]},{"type":"text","text":"。這可能是 seL4 開發者體驗的一個重大改進。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"總體設計"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"seL4 微內核可充當虛擬機監控器(Hyperviser)。它可以在相同的硬件上並行啓動 seL4 實時操作系統和一個 Linux 操作系統(稱爲客戶操作系統)。Linux 客戶操作系統具有完整的文件系統、網絡、用戶賬戶、shell 和 CLI 的功能和工具,但是它並非實時的。seL4 方面是實時的,但它是無頭(headless)的。我們的方法是在客戶 Linux 中運行 WasmEdge 代理。在客戶 Linux 中,我們可以上傳並存儲 WasmEdge 字節碼文件,然後使用代理熱部署並使用安裝在 seL4 中的 WasmEdge 運行器來執行字節碼。該架構如下所示:"}]},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/bb\/2d\/bb22d145b959e0047a802c83a79bc92d.png","alt":null,"title":"","style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這種代理和運行器架構允許我們將客戶 Linux 的易用性與 seL4 的健壯性、安全性和實時性能相結合。"}]},{"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":"這種設計提出了一種有趣的可能性。在 seL4 上,我們也許會運行一個成熟的 Kubernetes pod,在客戶操作系統中管理和編排 WasmEdge 應用。這是該團隊積極研究的一個領域。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"示例 WebAssembly 應用"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"WasmEdge 可以在 seL4 上運行任何 WebAssembly 字節碼應用程序。本演示中的 WebAssembly 應用程序樣本是由 C 和 Rust 源代碼編譯而成。"}]},{"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":"nbody-c.wasm 是一個用 C 語言對 N 體問題進行數值逼近的程序。然後,它從 "},{"type":"link","attrs":{"href":"https:\/\/benchmarksgame-team.pages.debian.net\/benchmarksgame\/program\/nbody-gcc-9.html","title":"","type":null},"content":[{"type":"text","text":"C 語言"}]},{"type":"text","text":"編譯成 WebAssembly 字節碼。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"hello.wasm 是一個 "},{"type":"link","attrs":{"href":"https:\/\/github.com\/second-state\/wasm-learning\/tree\/master\/cli\/hello","title":"","type":null},"content":[{"type":"text","text":"Rust 程序"}]},{"type":"text","text":",用於返回字符串到控制檯。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"修補用於 wasme\/dge 運行器的 seL4"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"seL4 中的標準庫不支持 WasmEdge 運行器開箱即用。爲了增加、開啓或更新一些重要特性,我們需要對這些庫進行修補。使用這些補丁構建了定製的 seL4 版本。"}]},{"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":"link","attrs":{"href":"https:\/\/github.com\/second-state\/wasmedge-seL4\/blob\/main\/patches\/02-llvm.patch","title":"","type":null},"content":[{"type":"text","text":"已修補的 LLVM 編譯器"}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/github.com\/second-state\/wasmedge-seL4\/blob\/main\/patches\/03-seL4_libs.patch","title":"","type":null},"content":[{"type":"text","text":"已修補的 seL4 系統庫"}]}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/github.com\/second-state\/wasmedge-seL4\/blob\/main\/patches\/06-vm-linux.patch","title":"","type":null},"content":[{"type":"text","text":"已修補的客戶 Linux 庫"}]}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"模擬器演示"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/github.com\/second-state\/wasmedge-seL4\/blob\/main\/build.sh","title":"","type":null},"content":[{"type":"text","text":"構建腳本"}]},{"type":"text","text":" 實現了構建 seL4 發行版的自動化,其中包括補丁庫、 WasmEdge 運行程序、一個客戶 Linux 操作系統(Ubuntu 20.04)和 WasmEdge 代理(稱爲 WasmEdge_emit)。"}]},{"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":"構建腳本要求 Ubuntu 20.04 系統安裝有開發者工具。點擊"},{"type":"link","attrs":{"href":"https:\/\/github.com\/actions\/virtual-environments\/blob\/main\/images\/linux\/Ubuntu2004-README.md#installed-apt-packages","title":"","type":null},"content":[{"type":"text","text":"此處"}]},{"type":"text","text":"可以看到這個系統需要的 apt 軟件包的完整列表。"}]},{"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":"完成了定製的 seL4 發行版之後,我們就可以在 QEMU 模擬器中運行它了。在 seL4 中,登錄到客戶 Linux 操作系統的命令 shell,上傳並保存 WebAssembly 字節碼文件,然後運行 wasmedge_emit 來部署並運行這些 WebAssembly 文件。該"},{"type":"link","attrs":{"href":"https:\/\/github.com\/second-state\/wasmedge-seL4\/blob\/main\/README.md","title":"","type":null},"content":[{"type":"text","text":"演示"}]},{"type":"text","text":"會帶你走完全程。你可以觀看"},{"type":"link","attrs":{"href":"https:\/\/youtu.be\/2Qu-Trtkspk","title":"","type":null},"content":[{"type":"text","text":"視頻"}]},{"type":"text","text":",瞭解它的操作!GitHub Action 日誌顯示了成功構建任務的控制檯輸出,而構件包含了構建結果。你只需下載構建到你自己的 Ubuntu 20.04 機器上的構件,然後啓動模擬器,運行 seL4 上的 WebAssembly 程序。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"未來計劃"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本文演示瞭如何使用模擬器來管理和執行 seL4 上的應用。下一步是在真實的硬件上運行 WasmEdge 應用程序。WasmEdge 的主要特點之一是可擴展性。從共享的本地庫向 WasmEdge 添加主機函數 API 很容易,這樣 WasmEdge WebAssembly 字節碼程序就可以訪問硬件,如 GPIO 引腳、攝像頭、USB 連接器、I\/O 板和 GPU。請繼續關注 seL4 上 WasmEdge 的更多用例演示!"}]},{"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"}],"text":"原文鏈接:"}]},{"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":"https:\/\/www.cncf.io\/blog\/2021\/11\/11\/containerization-on-the-edge\/"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章