Skip to content

Commit 2e81a2e

Browse files
committed
Add WasmEdge integration docs
Signed-off-by: wrongerror <[email protected]>
1 parent 8af52e7 commit 2e81a2e

File tree

3 files changed

+150
-1
lines changed

3 files changed

+150
-1
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: "WasmEdge Integration"
3+
linkTitle: "WasmEdge Integration"
4+
weight: 3380
5+
description:
6+
---
7+
8+
## WasmEdge Integration
9+
10+
`WasmEdge` is a lightweight, high-performance, and extensible WebAssembly runtime for cloud native, edge, and decentralized applications. It powers serverless apps, embedded functions, microservices, smart contracts, and IoT devices.
11+
12+
OpenFunction now supports building and running wasm functions with `WasmEdge` as the workload runtime.
13+
14+
> You can find the WasmEdge Integration proposal [here](https://github.com/OpenFunction/OpenFunction/blob/main/docs/proposals/20230223-wasmedge-integration.md)
15+
16+
### Function Build
17+
18+
When the value of the `spec.workloadRuntime` field is `wasmedge` or the annotations of the Function CR contains `module.wasm.image/variant: compat-smart`,
19+
`spec.build.shipwright.strategy` will be automatically generated based on the `ClusterBuildStrategy` named `wasmedge`.
20+
21+
### Function Serving
22+
23+
When the value of the `spec.workloadRuntime` field is `wasmedge` or the annotations of the Function CR contains `module.wasm.image/variant: compat-smart`:
24+
- If `spec.serving.annotations` does not contain `module.wasm.image/variant`, `module.wasm.image/variant: compat-smart` will be automatically generated into `spec.serving.annotations`
25+
- If `spec.serving.template.runtimeClassName` field is not set, the value of this field will be automatically set to `openfunction-crun`
26+
27+
> If your kubernetes cluster is in a public cloud, such as `azure`, you can set `spec.serving.template.runtimeClassName` to override the default `runtimeClassName`.
28+
29+
## Build and run wasm functions
30+
31+
> To setup `WasmEdge` workload runtime in kubernetes cluster and push images to a container registry,
32+
> please refer to the [prerequisites](../../getting-started/Quickstarts/prerequisites) section for more info.
33+
34+
1. Create a wasm function
35+
36+
```shell
37+
cat <<EOF | kubectl apply -f -
38+
apiVersion: core.openfunction.io/v1beta1
39+
kind: Function
40+
metadata:
41+
name: wasmedge-http-server
42+
spec:
43+
workloadRuntime: wasmedge
44+
image: openfunctiondev/wasmedge_http_server:0.1.0
45+
imageCredentials:
46+
name: push-secret
47+
build:
48+
dockerfile: Dockerfile
49+
srcRepo:
50+
revision: main
51+
sourceSubPath: functions/knative/wasmedge/http-server
52+
url: https://github.com/OpenFunction/samples
53+
port: 8080
54+
route:
55+
rules:
56+
- matches:
57+
- path:
58+
type: PathPrefix
59+
value: /echo
60+
serving:
61+
runtime: knative
62+
scaleOptions:
63+
minReplicas: 0
64+
template:
65+
containers:
66+
- command:
67+
- /wasmedge_hyper_server.wasm
68+
imagePullPolicy: IfNotPresent
69+
livenessProbe:
70+
initialDelaySeconds: 3
71+
periodSeconds: 30
72+
tcpSocket:
73+
port: 8080
74+
name: function
75+
EOF
76+
```
77+
78+
2. Check the wasm function status
79+
80+
```shell
81+
kubectl get functions.core.openfunction.io -w
82+
NAME BUILDSTATE SERVINGSTATE BUILDER SERVING ADDRESS AGE
83+
wasmedge-http-server Succeeded Running builder-4p2qq serving-lrd8c http://wasmedge-http-server.default.svc.cluster.local/echo 12m
84+
```
85+
86+
3. Access the wasm function
87+
88+
Once the `BUILDSTATE` becomes `Succeeded` and the `SERVINGSTATE` becomes `Running`, you can access this function through the address in the `ADDRESS` field:
89+
90+
```shell
91+
kubectl run curl --image=radial/busyboxplus:curl -i --tty
92+
curl http://wasmedge-http-server.default.svc.cluster.local/echo -X POST -d "WasmEdge"
93+
WasmEdge
94+
```

content/en/docs/getting-started/Quickstarts/prerequisites.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,43 @@ Async functions can be triggered by events in message queues like Kafka, here yo
156156
157157
```shell
158158
$ kafkacat -L -b <kafka-server>-kafka-brokers:9092
159-
```
159+
```
160+
161+
## WasmEdge
162+
163+
Function now supports using `WasmEdge` as workload runtime, here you can find steps to setup the `WasmEdge` workload runtime in a Kubernetes cluster (with `containerd` as the container runtime).
164+
165+
> You should run the following steps on all the nodes (or a subset of the nodes that will host the wasm workload) of your cluster.
166+
167+
1. **WasmEdge**
168+
169+
The easiest way to install WasmEdge is to run the following command. Your system should have git and curl installed.
170+
```shell
171+
wget -qO- https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local
172+
```
173+
174+
2. **crun**
175+
176+
The crun project has WasmEdge support baked in. For now, the easiest approach is just download the binary and move it to `/usr/local/bin/`
177+
```shell
178+
wget https://github.com/OpenFunction/OpenFunction/releases/latest/download/crun-linux-amd64
179+
mv crun-linux-amd64 /usr/local/bin/crun
180+
```
181+
If the above approach does not work for you, please refer to [build and install a crun binary with WasmEdge support.](https://wasmedge.org/book/en/use_cases/kubernetes/container/crun.html)
182+
183+
3. **containerd**
184+
185+
Edit the configuration `/etc/containerd/config.toml`, add the following section to setup crun runtime, make sure the BinaryName equal to your crun binary path
186+
```
187+
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun]
188+
runtime_type = "io.containerd.runc.v2"
189+
pod_annotations = ["*.wasm.*", "wasm.*", "module.wasm.image/*", "*.module.wasm.image", "module.wasm.image/variant.*"]
190+
privileged_without_host_devices = false
191+
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options]
192+
BinaryName = "/usr/local/bin/crun"
193+
```
194+
195+
Restart containerd service:
196+
```shell
197+
sudo systemctl restart containerd
198+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: "Create Wasm Functions"
3+
linkTitle: "Create Wasm Functions"
4+
weight: 2260
5+
description:
6+
---
7+
8+
> Before you creating any functions, make sure you've installed all the [prerequisites](../prerequisites)
9+
10+
Here you can find wasm function examples:
11+
12+
| Language | Wasm Functions | Runtime |
13+
|----------|------------------------------------------------------------------------------------------------------------------|----------|
14+
| Rust | [wasmedge-http-server](https://github.com/OpenFunction/samples/tree/main/functions/knative/wasmedge/http-server) | wasmedge |
15+
16+
> You can find more info about these Function [here](../../../concepts/wasmedge_integration/)

0 commit comments

Comments
 (0)