This project aims to demonstrate how to deploy .net wasm containers to Kubernetes.
See https://github.com/dotnet/dotnet-wasi-sdk for more details
To get started you can create a simple .net console app with
dotnet new console -o WasmConsoleApp
cd WasmConsoleApp
dotnet add package Wasi.Sdk --prerelease
dotnet build
This should produce a wasm binary under bin/Debug/net7.0/WasmConsoleApp.wasm
.
You can try it out by running wasmtime bin/Debug/net7.0/WasmConsoleApp.wasm
$ wasmtime bin/Debug/net7.0/WasmConsoleApp.wasm
Hello, World!
Add a Dockerfile with content, more info on scratch here
FROM --platform=$BUILDPLATFORM scratch
COPY ./bin/Debug/net7.0/WasmConsoleApp.wasm /WasmConsoleApp.wasm
ENTRYPOINT [ "WasmConsoleApp.wasm" ]
Push image to docker hub
docker login
docker buildx build -t dotnet-wasm:latest .
docker image tag dotnet-wasm:latest <username>/dotnet-wasm:latest
Create a new deployment file called deployment.yaml
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: crun
handler: crun
---
apiVersion: batch/v1
kind: Job
metadata:
creationTimestamp: null
name: wasm-test
spec:
template:
metadata:
annotations:
module.wasm.image/variant: compat-smart
creationTimestamp: null
spec:
containers:
- image: <username>/dotnet-wasm:latest
name: wasm-test
resources: {}
restartPolicy: Never
runtimeClassName: crun
backoffLimit: 1
Apply the file to your local cluster
microk8s kubectl apply -f deployment.yaml
Verify log output from pod