Rishit-dagli / msft-reactor-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Microsft Reactor Demo

Demo 1: Run a simple Rust app locally with Wasm

  1. Install wasmtime
curl https://wasmtime.dev/install.sh -sSf | bash
  1. Install rust with rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install the wasm32-wasi target
rustup target add wasm32-wasi
  1. Run the example
cd hello-world
cargo build --target wasm32-wasi --release
wasmtime target/wasm32-wasi/release/hello-world.wasm 
cd ..

Demo 2: Run a Rust app locally

  1. Install the wasm32-wasi target
rustup target add wasm32-wasi
  1. Build the example
cd tensorflow-mobilenet-v2
cargo build --target wasm32-wasi --release
  1. Run the example
wasmtime target/wasm32-wasi/release/example-tensorflow-mobilenet-v2.wasm --dir=.
  1. AOT Compilation

Let's now do an inference but this time with AOT compilation. Notice closely the time differences!

wasmtime compile target/wasm32-wasi/release/example-tensorflow-mobilenet-v2.wasm
wasmtime example-tensorflow-mobilenet-v2.cwasm --allow-precompiled --dir=.
cd ..

Demo 3: WebAssembly Text Format

  1. Install wabt
wget https://github.com/WebAssembly/wabt/releases/download/1.0.29/wabt-1.0.29-ubuntu.tar.gz
tar zxf wabt-1.0.29-ubuntu.tar.gz
  1. Convert Wasm to WAT
./wabt-1.0.29/bin/wasm2wat hello-world/target/wasm32-wasi/release/hello-world.wasm --output=hello-world.wat

Demo 4: WASI Node pools on AKS

  1. Register the WasmNodePoolPreview feature
az feature register --namespace "Microsoft.ContainerService" --name "WasmNodePoolPreview"

Running this command should show that the feature is registered:

az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/WasmNodePoolPreview')].{Name:name,State:properties.state}"

Refresh the registration of the ContainerService resource:

az provider register --namespace Microsoft.ContainerService
  1. Install the aks-preview Azure CLI extension
az extension add --name aks-preview
  1. Create a new AKS cluster
az group create --name wasmRG -l westus
az aks create --resource-group wasmRG --name myAKScluster2
  1. Add a WASM/WASI node pool to an existing AKS Cluster
az aks nodepool add \
    --resource-group wasmRG \
    --cluster-name myAKScluster2 \
    --name mywasipool \
    --node-count 1 \
    --workload-runtime wasmwasi

Verify the runtime:

az aks nodepool show -g reactor-demo --cluster-name myAKScluster2 -n mywasipool | jq '.workloadRuntime'
  1. Configure kubectl
az aks get-credentials -n myAKScluster2 -g wasmRG
  1. Get the internal IP of the WASI node
kubectl get nodes -o wide
  1. Run a simple deployment
kubectl apply -f wasi-deployment/wasi-example.yaml
  1. Create a reverse proxy

Update the values.yaml according to the internal IP of the load balancer which you can get with kubectl get svc.

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install hello-wasi bitnami/nginx -f wasi-deployment/values.yaml
kubectl get svc
  1. Try the deployment
curl EXTERNAL_IP/hello

Demo 5: Run a Rust app with WASM in AKS

  1. Install wasm-to-oci
wget https://github.com/engineerd/wasm-to-oci/releases/download/v0.1.2/linux-amd64-wasm-to-oci
mv linux-amd64-wasm-to-oci wasm-to-oci
chmod +x wasm-to-oci
sudo cp wasm-to-oci /usr/local/bin
  1. Create a new container registry
az acr create -n reactordemo -g wasmRG --sku Standard
az acr login -n reactordemo
az acr update --name reactordemo --anonymous-pull-enabled
  1. Build the project:
cd aks-demo
cargo build --target wasm32-wasi --release
  1. Push the WASM image to the container registry
wasm-to-oci push target/wasm32-wasi/release/wasi_example_main.wasm reactordemo.azurecr.io/reactordemo:1.0.0

Verify the push:

az acr repository list -n reactordemo
az acr repository show -n reactordemo --image reactordemo:1.0.0
  1. Deploy the pod
kubectl apply -f pod.yaml
  1. Test the deployment
curl EXTERNAL_IP

About

License:Apache License 2.0


Languages

Language:Rust 100.0%