Sealos cloud operating system integrates runwasi with one click, unlocking the unlimited potential of Wasm

WebAssembly (often abbreviated to Wasm) is a low-level programming language designed for web browsers. It is designed to provide a faster and more efficient way to execute code than traditional JavaScript to compensate for JavaScript's performance shortcomings. By using a binary format, WebAssembly provides faster parsing and execution than traditional JavaScript.

Original link:https://forum.laf.run/d/1095

Wasm expands into cloud native space

However, with the development of time, its application scope hasexpanded to the cloud native field. Compared with containers and virtual machines, WebAssembly has the following advantages:

  1. Performance and security: With the development of the cloud native ecosystem, the demand for high performance and security is growing. WebAssembly is an attractive choice because of its fast, secure, and sandboxed features.
  2. Cross-platform features: The cross-platform nature of WebAssembly makes it well-suited for cloud-native environments, as it can run in any environment that supports the Wasm runtime, with the underlying hardware or operations The system is irrelevant.
  3. Lightweight: Compared with traditional virtual machine and container technologies, Wasm provides a more lightweight solution, which is suitable for cloud-native applications that require rapid expansion and scaling. Especially important, such as function computing scenarios.
  4. Microservices and edge computing: Wasm is suitable for use in microservice architecture and edge computing scenarios because it can provide fast startup time and higher resource utilization efficiency.

With the maturity of technology and the development of the community, more and more tools and platforms have been developed to support the use of WebAssembly in cloud native environments,runwasi a> is one of them. It is a Containerd plug-in that integrates the Wasm runtime into Containerd to support the use of Containerd to create and manage Wasm applications.

This article will introduce how to quickly integrate runwasi in Sealos cloud operating system and use runwasi to run Wasm applications.

⚠️ Note: runwasi is currently in Alpha version and is not recommended for use in production environments.

Introduction to runwasi

Let’s first take a look at runwasi’s aggressive logo:

Before understanding runwasi, let’s first clarify a few concepts:

WebAssembly (Wasm) runtime

  • WebAssembly Basics: WebAssembly provides a sandbox environment in which precompiled binary code can be executed with near-native performance. These code modules are platform independent and can run in any environment that supports Wasm.
  • Wasm Runtime: This is a software stack that loads, verifies, compiles, and ultimately executes Wasm binaries. For example, Wasmtime or Wasmer are such runtimes.

Containerd architecture

ContainerdIt is an industry-standard container runtime that is responsible for the creation, starting, stopping and management of containers. Its architecture is designed to be modular and its functions can be extended through plug-ins. This includes snapshot plugins, runtime plugins, etc. runwasi is one of the snapshot plugins.

How runwasi works

  1. As a plugin: runwasi Exists as a Containerd snapshot plugin that enables Wasm applications to run as containers.
  2. Load Wasm application: When Containerd requests to start a container, the runwasi plugin is responsible for loading the Wasm application.
  3. Wasm runtime integration:runwasi Use a Wasm runtime (such as Wasmtime) to execute Wasm applications. This means it handles the loading, validation, and execution of Wasm binaries.
  4. Containerized Wasm applications: With runwasi, Wasm applications are managed under Containerd similar to traditional Runs like a container application, but actually executes within the Wasm runtime.

Sealos integration runwasi

Next we will demonstrate how to integrate runwasi in the Sealos cloud operating system. The steps are very simple and only require one command.

Sealos provides three different cluster images: labring/containerd-shim-wasmtime, labring/containerd-shim-wasmedge and labring/containerd-shim-wasmer, which respectively correspond to three different Wasm runtimes: WasmEdge, Wasmtime and Wasmer.

Taking the Wasmtime runtime as an example, you only need to execute the following command to integrate runwasi into the Sealos cluster:

$ sealos run docker.io/labring/containerd-shim-wasmtime:v0.3.0

Then write a Wasm application using Rust:

// hello.rs

use std::thread::sleep;

fn main() {
    loop {
        sleep(std::time::Duration::from_secs(5));
        println!("{}", "This is from a main function from a wasm module");
    }
}

Compile and run:

$ rustup target add wasm32-wasi
$ rustc quick-start.rs --target wasm32-wasi
$ wasmtime quick-start.wasm
This is from a main function from a wasm module

The wasm file has been compiled in this warehouse:https://github.com/labring-actions/wasi-image/tree/main/applications/quick-start/ main

You can clone the repository, enter applications/quick-start/main, and then execute the following command to build the wasi image and push it to the Sealos local image repository:

$ sealos build --platform "wasi/wasm" -t sealos.hub:5000/quick-start:latest .
$ sealos push sealos.hub:5000/quick-start:latest

Write a Job configuration manifest:

# wasm-demo.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: wasm-demo
spec:
  template:
    metadata:
      labels:
        app.kubernetes.io/name: wasm-demo
    spec:
      containers:
        - name: wasm-demo
          image: sealos.hub:5000/quick-start:latest
      runtimeClassName: runwasi-wasmtime # 修改成对应的 runtime 名字
      restartPolicy: Never

Create a job:

$ kubectl apply -f wasm-demo.yaml

View the demo log:

$ kubectl logs jobs/wasm 
This is from a main function from a wasm module

Guess you like

Origin blog.csdn.net/alex_yangchuansheng/article/details/134416021