Containerless! How to Run WebAssembly Workloads on Kubernetes with Rust

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • wasmtime

    A fast and secure runtime for WebAssembly

  • Though initially designed for the web, WebAssembly proved to be an ideal format for writing platform and language-agnostic applications. You may be aware of something similar in the container world—Docker containers. People, including Docker co-founder Solomon Hykes, recognized the similarity and acknowledged that WebAssembly is even more efficient since it's fast, portable, and secure, running at native speeds. This means that you can use WebAssembly alongside containers as workloads on Kubernetes. Another WebAssembly initiative known as WebAssembly System Interface (WASI) along with the Wasmtime project make this possible.

  • krustlet

    Kubernetes Rust Kubelet

  • Now you need to bootstrap Krustlet. For this, you will need kubectl installed and a kubeconfig that has access to create Secrets in the kube-system namespace and can approve CertificateSigningRequests. You can use these handy scripts from Krustlet to download and run the appropriate setup script for your OS:

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • wasi-libc

    WASI libc implementation for WebAssembly

  • Though initially designed for the web, WebAssembly proved to be an ideal format for writing platform and language-agnostic applications. You may be aware of something similar in the container world—Docker containers. People, including Docker co-founder Solomon Hykes, recognized the similarity and acknowledged that WebAssembly is even more efficient since it's fast, portable, and secure, running at native speeds. This means that you can use WebAssembly alongside containers as workloads on Kubernetes. Another WebAssembly initiative known as WebAssembly System Interface (WASI) along with the Wasmtime project make this possible.

  • kubernetes

    Production-Grade Container Scheduling and Management

  • Don't worry about the status. It's normal for a workload that terminates normally to have ExitCode:0. Let's check the logs for the pod by running kubectl logs.

  • book

    The Rust and WebAssembly Book (by rustwasm)

  • I previously wrote a blog post about why Rust is a great language for the future, Tl;Dr; Rust is secure and fast without the compromises of most modern languages, and Rust has the best ecosystem and tooling for WebAssembly. So Rust + Wasm makes it super secure and fast.

  • wasi-experimental-http

    Discontinued Experimental outbound HTTP support for WebAssembly and WASI

  • Let's run the workload locally using Wasmtime, a small JIT-style runtime for Wasm and WASI. Since Wasmtime doesn't support networking out of the box, we need to use the wrapper provided by wasi-experimental-http. You can build it from source using the below command.

  • kind

    Kubernetes IN Docker - local clusters for testing Kubernetes

  • First, you need to prepare a cluster and install Krustlet on the cluster to run WebAssembly on it. I'm using kind to run a local Kubernetes cluster; you can also use MiniKube, MicroK8s, or another Kubernetes distribution.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • tokens

  • First, you need to log in to GitHub Package Registry using docker login. Create a personal access token on GitHub with the write:packages scope and use that to log in to the registry.

  • wasm-to-oci

    Use OCI registries to distribute Wasm modules

  • # Install for Linux curl -LO https://github.com/engineerd/wasm-to-oci/releases/download/v0.1.2/linux-amd64-wasm-to-oci # move to any location that is added to your PATH variable mv linux-amd64-wasm-to-oci ~/bin/wasm-to-oci

  • okta-rust-webassembly-k8s-example

    An example Rust WebAssembly application as a Kubernetes workload

  • Awesome. You have successfully created a Wasm workload using Rust and deployed it to a Kubernetes cluster without using containers. If you'd like to take a look at this solution in full, check out the GitHub repo.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts