Adding WASM support to Knative Functions #1489
Replies: 15 comments 9 replies
-
Hey @aslom I'm not sure I know the "simplest" way but I'll share my work so far: At an abstract level I see two approaches to running WASM in knative.
Here is a matrix that compares the two approaches. It's not exhaustive but what I have been considering. I have ordered them based on conversations I am having with 3rd Parties but other use cases may give a different priority.
Given the priorities I have I looked at the OCI hosted option using WASMedge specifically in the following area: configuring a knative environmentWASMEdge provides guidance on using the runtime with Kubernetes and knative https://wasmedge.org/book/en/use_cases/kubernetes.html https://wasmedge.org/book/en/use_cases/kubernetes/kubernetes/knative.html I've taken that guidance and packaged it into a deployment system for IKS and OpenShift to validate that it can be performed on public cloud providers with both Knative and K8s workloads. I have a bit of experience with providing host configuration on public cloud and the pattern should be repeatable for most other cloud providers. https://github.com/uirlis/wasi-crun-deployer code sampleTo validate the deployment I also created a running example of the knative docs rust code mapped to WASMEdge OCI approach. WASMEdge Example https://github.com/uirlis/helloworld-rust-wasi templateI have started to look at what would be required to create a kn func template project for both serving and eventing scenarios based on the templates Original Code https://github.com/knative/func/tree/1a6c42f01baff54f68a92a5fd59ed8f339837338/templates/rust WASMEdge Example https://github.com/uirlis/func-rust-wasi The majority of the code is in place however a build system has not been created but I would expect that to be achievable. cloud eventsTo support the template cloudevents project I have opened a PR to land hyper-wasi support into the rust cloud events sdk cloudevents/sdk-rust#202 other observations:
next items
Hopefully this is useful information and if the WASMEdge samples or templates are of interest I'd be happy to PR them. |
Beta Was this translation helpful? Give feedback.
-
I'm a little surprised that enabling wasm in a FaaS implies that wasm should control network sockets. Maybe I'm misunderstanding, but I think usually a FaaS does that part on behalf of the function, which makes the function impls a lot simpler. Specific to wasm, if network control is put out of scope it is a lot more portable, just like any other wasm FaaS. Am I missing something? |
Beta Was this translation helpful? Give feedback.
-
@No9 thank for detailed description of your experiments. Based on your experience what do you think is the simplest way to enable running WASM with Knative using buildpacks for knative/func? |
Beta Was this translation helpful? Give feedback.
-
/cc @cardil |
Beta Was this translation helpful? Give feedback.
-
Hey @aslom @codefromthecrypt Love this line of questioning. That said we should look at the likes of runwasi and krustlet to understand how |
Beta Was this translation helpful? Give feedback.
-
Hey @aslom Update on the E2E Scenario git clone https://github.com/knawd/buildpack
cd buildpack
pack build helloworld-rust-wasi --path ./apps/rust/helloworld-rust-wasi --buildpack ./buildpacks/rust \
--builder quay.io/knawd/builder:rust --docker-host=inherit -v --trust-builder
podman run --rm --annotation module.wasm.image/variant=compat-smart -p 8080:8080 \
--entrypoint /layers/knawd_rust/wasi/hellorust.wasm helloworld-rust-wasi Here is a list of outstanding issues to get a WASMEdge enabled crun integrated with
|
Beta Was this translation helpful? Give feedback.
-
@No9 I was looking to solve the limitation you mentioned ("WASMEdge seems to be limited to JS, Rust and C") and it seems that today the easiest way to host any language will be to use WAGI as all needed in runtime is for the binary wasm to be compiled with WASI and read input form environment variables and produce output to standard out (WAGI is inspired by CGI). I will join today Func WG to talk about it |
Beta Was this translation helpful? Give feedback.
-
@aslom Seems like a reasonable conclusion - I think my goal of a scratch based image that could be used in kn and at edge was cutting across too many previous decisions. Also the WAGI approach will give the ability to support multiple wasm runtimes which will be good for the ecosystem as well. |
Beta Was this translation helpful? Give feedback.
-
I have got it now to work with WAGI: #1551 (comment) |
Beta Was this translation helpful? Give feedback.
-
As Wasm is evolving we should update it in 2024. In particular to take advantage of the latest developments such as support for outbound HTTP and CLI options in WASI previeew 2: https://github.com/WebAssembly/WASI/tree/main/preview2 |
Beta Was this translation helpful? Give feedback.
-
I think we have some new information to add to this discussion now, @aslom? |
Beta Was this translation helpful? Give feedback.
-
We had quick discussion in Tuesday meeting - here is gist of it: @lkingland mentioned that initial function code deployment for new users is major hurdle, in particular getting container registry configured and working After discusssion we think that one use case could be ultra fast Knative func deployments - as WASM is already a lightweight container format we could have a shell container that is deployed in dev mode and then WASM code is located into it. No need for users for container registry as the shell container is provided and WASM blob could be send directly to the container to run Other use case/scenrio could be to do it for edge scenarios where WASM code is deployed and a web page is available. This takes advantage of WASM to generate code once and run it anywhere without need to recompile for what hardware is used on edge. |
Beta Was this translation helpful? Give feedback.
-
Yes about the first - I would focus on maximum speed so no registry and directly streaming wasm as you compile it into Knative func container that hosts WASM in dev mode. About the second: we should identify two (more?) target devices such as Android smartphone and Raspberry PI? |
Beta Was this translation helpful? Give feedback.
-
One way to accomplish very quick deployments for dev version is to use container that has sshd running and then sftp or rsync files from local dir to remote container over kubectl port-forward tunnel. |
Beta Was this translation helpful? Give feedback.
-
Today in WG meeting we talked about options to get code form local dir into remote container. One is to use SSHD but without any admin privileges configured just for one user. One port exposed to do ssh over kubectl port-forward to copy files and also ssh or kubectl to forward port for debugging - IDE would open connection to the port and allow remote breakpoints. Other option mentioned by @matejvasek is to use stdin and stdout to connect to remote container that may include sending tarball that is then extracted remotely. (my understanding of it is limited) |
Beta Was this translation helpful? Give feedback.
-
What would be the simplest way to enable running WASM with Knative? Enable with different WASM runtimes?
Beta Was this translation helpful? Give feedback.
All reactions