Crun natively supports running wasm/wasi workload on using wasmedge
, wasmer
, wasmtime
and wamr
.
Each one of them (wasmedge
, wasmer
, wasmtime
and wamr
) comes with their own set of unique features.
For instance wasmer
can compile your .wat
on the fly. Similarly wasmedge
has its own perks. wamr
has a layered JIT architecture which can tier up during runtime.
Crun can support only one of them at a time. Please build crun with whatever runtime suits you the best.
- Make sure oci config propagated by your CRI implementation contains annotations
run.oci.handler: wasm
ormodule.wasm.image/variant=compat
. - Entrypoint must point to a valid .wat (webassembly text)
**wasmer-only**
or .wasm (webassembly binary). - If your kubernetes infrastructure is using service-mesh, proxy or in general side-cars pattern then in such cases recommended annotations would be
module.wasm.image/variant=compat-smart
orrun.oci.handler: wasm-smart
.
So spec generated by CRI implementation must contain annotation something like.
...
"annotations": {
"run.oci.handler": "wasm"
},
...
- Following features works completely out if the box once
cri-o
is usingcrun
built withwasm
support. - Configure
cri-o
to usecrun
instead ofrunc
by editing config at/etc/crio/crio.conf
read more about it here https://docs.openshift.com/container-platform/3.11/crio/crio_runtime.html#configure-crio-use-crio-engine - As of
cri-o
version1.31
it defaults tocrun
, but the bundledcrun
may not have been built withwasm
support. - Restart
cri-o
bysudo systemctl restart crio
cri-o
automatically propagates pod annotations to container spec. So we don't need to do anything.
apiVersion: v1
kind: Pod
metadata:
name: pod-with-wasm-workload
namespace: mynamespace
annotations:
module.wasm.image/variant: compat
spec:
containers:
- name: wasm-container
image: myrepo/mywasmimage:latest
Containerd
supports switching container runtime via custom config defined at/etc/containerd/config.toml
- Configure
containerd
to usecrun
by making sure runtime binary points tocrun
read more about config here https://github.com/containerd/containerd/blob/main/docs/cri/config.md - Configure
containerd
to whilelistwasm
annotations so they could propagated to OCI spec. By settingpod_annotations
in the config.
pod_annotations = ["*.wasm.*", "wasm.*", "module.wasm.image/*", "*.module.wasm.image", "module.wasm.image/variant.*"]
- Restart
containerd
bysudo systemctl start containerd
- Now
containerd
should propagatewasm
pod annotations to containers.
apiVersion: v1
kind: Pod
metadata:
name: pod-with-wasm-workload
namespace: mynamespace
annotations:
module.wasm.image/variant: compat
spec:
containers:
- name: wasm-container
image: myrepo/mywasmimage:latest