How To Run WebAssembly on Kubernetes
The other day, I was chatting with a platform engineer. “You do WebAssembly stuff, right? It seems like everyone is talking about it as the new way to do serverless. What does that mean?” Originally conceived as a browser technology, WebAssembly (Wasm) is showing up in many places now. In the Kubernetes world, it is providing a new way of running serverless — sometimes called FaaS or Functions as a Service.
Kubernetes just crossed its tenth anniversary. In its early days, in 2015 and 2016, we talked about Kubernetes as a Docker orchestrator. It sat atop Docker and scheduled containers to run on Docker instances.
But Docker itself was not really on board with this. They had created their orchestrator, Swarm, which they believed was superior to Kubernetes. And there was some bad blood. DockerCon disallowed talks about Kubernetes, yet Docker folks showed up at KubeCon to discuss how Swarm was better than Kubernetes. Years later, we’ve all forgiven and moved on. But in that moment, the conflict between the two led Kubernetes in an exciting direction. Instead of remaining Docker-centric, the Kubernetes developers took one hop up the abstraction layer and began calling Kubernetes a container orchestrator. And they began attempts to support other container runtimes, such as CoreOS’s rkt (pronounced “rocket”).
Abstracting from the details of the container runtime has big advantages. An area whose innovation was controlled by only one company was suddenly open to all. Red Hat, Samsung, Microsoft, Google, and many other reputable engineering organizations could bring their formidable talent to the field.
Now, a decade later, the benefits are clear. Containerd is now a well-established project governed by the Cloud Native Computing Foundation (CNCF), and it offers so much flexibility that developers have added a variety of containerd “shims” to support around a dozen different low-level runtimes.
One of the technologies supported this way is Wasm.
From the Browser to the Cloud
Wasm was developed to solve a specific problem: Take library code from languages like C, C++, Rust, Go, and Zig and make them available to JavaScript code running in the web browser. In a way, Wasm was designed to rectify the mistakes made with Java Applets, Silverlight, Flash, and other non-JS browser languages. In this regard, Wasm has been successful. Every mainstream browser supports Wasm, and from Office 365 to Figma, Wasm powers some sophisticated web apps.
But Wasm’s security model, cross-platform support, and compact bytecode format make it a good fit for other applications beyond the browser. BBC and Amazon use it in their embedded streaming players. Shopify uses it as a plugin language. SingleStore supports Wasm-stored procedures in its database. Most interestingly, Wasm has been making inroads on the cloud.