2

使用 K8s 等现有容器工具管理 WebAssembly 应用

 2 years ago
source link: https://my.oschina.net/u/4532842/blog/5321263
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用 K8s 等现有容器工具管理 WebAssembly 应用

现在我们可以利用 Kubernetes、 Docker 和 CRI-O 等容器工具来部署、管理和运行轻量级 WebAssembly 应用程序啦。

本文将演示 Kubernetes 生态系统工具如何与 WasmEdge WebAssembly 应用程序一起运行。

WasmEdge runtime

与 Docker 相比,WebAssembly 在启动时可以快100倍,拥有更小的内存和磁盘占用空间,并且有一个定义更好的安全沙箱。然而,这其中的取舍是 WebAssembly 需要自己的语言 SDK 和编译器工具链,使其成为比 Docker 受限制的开发环境。现在,WebAssembly 越来越多地用于 Docker 容器很难部署的边缘计算场景,或者是应用程序性能至关重要的情况下。

像 Docker 这样的应用程序容器的最大优势之一是丰富的工具生态。好消息是,你可以使用完全相同的工具来管理 WebAssembly 应用程序,从而使 docker 这样的 Linux 容器和 WebAssembly 应用程序能够在同一个系统中并列运行。

WebAssembly 应用与 Linux 容器肩并肩运行

demo 应用

Demo 应用程序是用 Rust 编写并编译成 WebAssembly 字节码,然后打包并发布在 Docker Hub 上的无操作系统容器镜像。然后我们将使用容器工具启动并运行这个 WebAssembly 应用镜像。

点击此处了解如何构建和发布此 WebAssembly 应用镜像

低级容器 runtime

容器镜像可以由任何符合 OCI 标准的容器 runtime (如 crun)启动。crun 项目内置了 WasmEdge 支持。使用下面的命令在 Ubuntu 上构建并安装一个具有 WasmEdge 支持的 crun 可执行二进制文件。

git clone https://github.com/containers/cruncd crun
./autogen.sh
./configure --with-wasmedge
make
sudo make install

高级容器 runtime

高级容器 runtime (如 CRI-O)从 registry (如 Docker Hub)拉取容器镜像,在磁盘上管理它们,并启动低级 runtime 来运行容器进程。

点击此处了解如何使用带有 crun 的 CRI-O 来拉取、启动和管理 WebAssembly 程序镜像

视频说明

Kubernetes

多数高级容器 runtime 都实现了 Kubernetes 的 CRI (Container Runtime Interface) 规范,因此可以使用 Kubernetes 工具管理它们。这意味着你可以使用 Kubernetes 工具在 pods 和 name spaces 中管理 WebAssembly 应用镜像。

Kubernetes:点击此处了解如何为 WebAssembly 应用镜像创建和运行 pods。

本文中,我们了解了如何使用容器工具拉取、启动、运行和管理 WasmEdge 应用程序。未来将支持更多的容器 runtime 和 Kubernetes 框架并列运行 Linux 容器和 WebAssembly 应用容器。敬情期待。

如果你对此有什么问题想要讨论,欢迎通过 GitHub issue 与我们讨论,或是加入 WasmEdge Slack Channel。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK