Demo Serving Rust HTTP via k8s, knative, wasmeredge
This template kicks off a Rust HTTP service that should give you zero problems deploying to WASM because there are zero dependencies.
Rust is a great general purpose programming language that uses AoT compilation to target native machine code. This makes Rust a great language to deploy to containers built FROM scratch or even compile to WASM for incredibly fast cold-start times.
WASM is a really tight compilation target. It's technically an intermediate bytecode representation, but it's much closer to native machine code (apparently) and so executes code at near-native speeds. One of the reasons people like it is because good browsers have a WASM runtime that allows you to basically execute Rust/ C code compiled for WASM right there in the browser. The other aspect of WASM is that it has really speedy cold start times and is likely to displace other runtimes in the cloud.
Dependencies
Function as a Service Deployments
Run Local Native
cargo run
Run Local Container
docker build . -t thenotary/first-test
docker run -p 7878:7878 -it --init thenotary/first-test
Run Local Wasmer
cargo wasix run --net
Deploy to WasmerEdge
You need a free account you can sign up for at wasmer.io.
wasmer deploy
curl https://first-test.wasmer.app
Deploy to k8s
These notes assume you already have a k8s cluster you can interact with via kubectl.
kubectl apply -f k8s/demo.yml
Deploy to Knative
These notes assume you already have knative deployed to your k8s cluster. To deploy a one-off FaaS service without a yaml, you can use:
kn service create hello \
--image \
--port 7878 \
--env TARGET=World
Alternatively deploy the yaml for the knative faas function:
kubectl apply -f knative/demo.yaml.tt
Deploy to Azure Container App
Setup the Infrastructure
TODO: Provide some tf for setting up container registry azurerm_container_app...
cd tf
tf init
tf apply
cd ..
Deploy and test the Function
./deploy_container_app_azure.sh