Skip to content

Commit 4afac10

Browse files
committed
README: add k8s kind and k3s demos
Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
1 parent 56ea23f commit 4afac10

File tree

1 file changed

+141
-4
lines changed

1 file changed

+141
-4
lines changed

README.md

Lines changed: 141 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ And make sure the shim binary must be in $PATH (that is the $PATH that container
129129
130130
This shim runs one per pod.
131131

132-
## Contributing
133-
134-
To begin contributing, learn to build and test the project or to add a new shim please read our [CONTRIBUTING.md](./CONTRIBUTING.md)
135-
136132
## Demo
137133

138134
### Installing the shims for use with Containerd
@@ -208,5 +204,146 @@ make test/k8s-oci-wasmtime
208204

209205
> note: We are using a kubernetes cluster to run here since containerd's ctr has a bug that results in ctr: `unknown image config media type application/vnd.wasm.config.v0+json`
210206
207+
### Demo 4: Running on Kubernetes
208+
209+
You can run WebAssembly workloads on Kubernetes using either Kind or k3s.
210+
211+
#### Using Kind
212+
213+
1. Install and configure dependencies:
214+
```bash
215+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-amd64
216+
chmod +x ./kind
217+
sudo mv ./kind /usr/local/bin/
218+
219+
make build-wasmtime
220+
sudo make install-wasmtime
221+
```
222+
223+
2. Create a Kind configuration:
224+
```yaml
225+
# kind-config.yaml
226+
kind: Cluster
227+
apiVersion: kind.x-k8s.io/v1alpha4
228+
name: runwasi-cluster
229+
nodes:
230+
- role: control-plane
231+
extraMounts:
232+
- hostPath: /usr/local/bin/containerd-shim-wasmtime-v1
233+
containerPath: /usr/local/bin/containerd-shim-wasmtime-v1
234+
```
235+
236+
3. Create and configure the cluster:
237+
```bash
238+
kind create cluster --name runwasi-cluster --config kind-config.yaml
239+
240+
kubectl cluster-info --context kind-runwasi-cluster
241+
242+
cat << EOF | docker exec -i runwasi-cluster-control-plane tee /etc/containerd/config.toml
243+
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]
244+
runtime_type = "io.containerd.wasmtime.v1"
245+
EOF
246+
247+
docker exec runwasi-cluster-control-plane systemctl restart containerd
248+
```
249+
250+
4. Deploy the demo application:
251+
```bash
252+
kubectl --context kind-runwasi-cluster apply -f test/k8s/deploy.yaml
253+
```
254+
255+
5. Check the logs:
256+
```bash
257+
kubectl --context kind-runwasi-cluster logs -l app=wasi-demo
258+
```
259+
where you should see the output of the demo application:
260+
261+
```console
262+
This is a song that never ends.
263+
Yes, it goes on and on my friends.
264+
Some people started singing it not knowing what it was,
265+
So they'll continue singing it forever just because...
266+
```
267+
268+
#### Using k3s
269+
270+
1. Install k3s and build the shim:
271+
```bash
272+
curl -sfL https://get.k3s.io | sh -
273+
274+
make build-wasmtime
275+
sudo make install-wasmtime
276+
```
277+
278+
2. Configure k3s to use the Wasm runtime:
279+
```bash
280+
sudo mkdir -p /var/lib/rancher/k3s/agent/etc/containerd/
281+
282+
cat << EOF | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl
283+
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]
284+
runtime_type = "io.containerd.wasmtime.v1"
285+
EOF
286+
287+
sudo systemctl restart k3s
288+
```
289+
290+
3. Deploy the demo application:
291+
```bash
292+
sudo k3s kubectl apply -f test/k8s/deploy.yaml
293+
```
294+
295+
4. Check the deployment:
296+
```bash
297+
sudo k3s kubectl wait deployment wasi-demo --for condition=Available=True --timeout=90s
298+
299+
sudo k3s kubectl get pods
300+
sudo k3s kubectl logs -l app=wasi-demo
301+
```
302+
303+
You should see "This is a song that never ends." repeated in the logs.
304+
305+
5. Clean up when done:
306+
```bash
307+
sudo k3s kubectl delete -f test/k8s/deploy.yaml
308+
309+
# Optionally uninstall k3s
310+
/usr/local/bin/k3s-uninstall.sh
311+
```
312+
313+
#### The `deploy.yaml` file
314+
315+
The deployment includes:
316+
```yaml
317+
apiVersion: node.k8s.io/v1
318+
kind: RuntimeClass
319+
metadata:
320+
name: wasm
321+
handler: wasm
322+
---
323+
apiVersion: apps/v1
324+
kind: Deployment
325+
metadata:
326+
name: wasi-demo
327+
spec:
328+
# ...
329+
template:
330+
spec:
331+
runtimeClassName: wasm # Use the wasm runtime class
332+
containers:
333+
- name: demo
334+
image: ghcr.io/containerd/runwasi/wasi-demo-app:latest
335+
```
336+
337+
338+
To see demos for other runtimes, replace `wasmtime` with `wasmedge`, `wasmer`, or `wamr` in the above commands.
339+
340+
In addition, check out the [Kubernetes + Containerd + Runwasi](https://wasmedge.org/docs/develop/deploy/kubernetes/kubernetes-containerd-runwasi) for more on how to run WasmEdge on Kubernetes.
341+
342+
211343
### WASI/HTTP Demo for `wasmtime-shim`
212344
See [wasmtime-shim documentation](./crates/containerd-shim-wasmtime/README.md#WASI/HTTP).
345+
346+
347+
## Contributing
348+
349+
To begin contributing, learn to build and test the project or to add a new shim please read our [CONTRIBUTING.md](./CONTRIBUTING.md)

0 commit comments

Comments
 (0)