Use Kubernetes and kind to Manage WebAssembly Apps

Jan 20, 2022 • 3 minutes to read

This article is based on Sven Pfennig’s presentation at the WasmEdge Community Meeting in Jan 2022. Pfennig discussed why and how to run WebAssembly apps in a Kubernetes cluster. Using kind and WasmEdge, he showcased a simple solution.

Please watch the original video here: https://www.youtube.com/watch?v=-oumohWVgSI&t=493s

Background

kind is Kubernetes In Docker, that is, to deploy all the components required by Kubernetes in a docker container. kind is a simple and easy-to-use version of Kubernetes, often used in local testing use cases.

WasmEdge is an OCI-compliant cloud-native WebAssembly runtime hosted by CNCF (Cloud Native Computing Foundation). It is one of the fastest WebAssembly runtimes on the market today. WasmEdge supports all WebAssembly standard extensions as well as non-standard extensions like Tensorflow inference, networking, KV storage, and image processing. Its language toolchain supports not only compiled languages such as C/C++, Rust, Swift, Kotlin and AssemblyScript, but also JavaScript and Python.

Why Kubernetes Community needs WasmEdge

Kubernetes managed microservices ad edge services gain popularity, there is increasing demand for lightweight containers that are appropriate for those light workloads.

WebAssembly (Wasm) is a high-performance runtime with a small footprint. Wasm has better security isolation and cross-platform support than Linux containers. Edge devices have very limited resources, and Linux containers are cumbersome and resource-intensive on edge devices. The application of Wasm can be only 1% of the size of a similar Linux container application, which will greatly release the computing resources of edge devices. Also, WasmEdge has almost no cold start time and outperforms Linux containers by a factor of 100.

Wasm is the best choice for the Kubernetes ecosystem.

Krustlet is great, but

Like WasmEdge, Krustlet is also a CNCF sandbox project. Krustlet uses Kubelet to orchestrate Wasm images in Kubernetes pods. But in Pfennig's case, although it is theoretically possible to use Krustlet to manage Wasm images in kind, it faces the following problems:

  • No CNI containers, no daemonsets
  • Tollerations needed to keep default containers away from krustlet nodes
  • No standard way to route traffic to the Pod

Therefore, if you want to use Krustlet, you need to make a lot of code modifications to kind, which is not in line with the design concept of the kind project, being clean and small.

WasmEdge + crun is more powerful and easy to use than Krustlet

crun is the most popular OCI container running program in the Kubernetes ecosystem. It supports Linux containers. Recently, the crun project has also officially added support for the WasmEdge container image, so that tools in the K8s ecosystem can manage WasmEdge with just some configuration of crun.

So based on the wasmedge-containers-examples repo, provided by the WasmEdge team, take Krustlets which can take the kind node to replace just runc by crun. Config needs to be adapted a bit. No code adaption with kind is needed. The standard kind can be used.

In addition, WasmEdge supports networking socket. So Wasm applications can directly use the network to implement features such as HTTP requests and services. Network support is a very important prerequisite for implementing microservices with Wasm.

What’s Next

In Kubernetes applications, a popular architecture is microservices, which split the functions of complex applications into independent containerized services. And WasmEdge is especially suitable for such use cases. WasmEdge can be used for distroless debugging, ephemeral containers, or as a Service Mesh or FaaS runtime, such as combined with Knative framework.

Pfennig shared how to use WasmEdge in Knative, and he also implemented the use of WasmEdge in Linkerd as the sidecar runtime. It’s recommended to take a look at Pfennig's kind-crun-WasmEdge GitHub repo.

Kubernetes combined with WasmEdge has a wide range of applications, a real game changer! Pfennig comments that the integration of Kubernetes with WebAssembly/WasmEdge is underrated and deserves more attention.

K8sCommunitycrunK8sKINDWasmEdge
A high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for automotive, cloud, AI, and blockchain applications