Skip to content

Instantly share code, notes, and snippets.

@alexeldeib
Last active October 21, 2022 22:26
Show Gist options
  • Save alexeldeib/08817955e6b02965728671ecf3ee26eb to your computer and use it in GitHub Desktop.
Save alexeldeib/08817955e6b02965728671ecf3ee26eb to your computer and use it in GitHub Desktop.
AKS wasm demo
# need an ingress controller ideally
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml
# wait a bit for nginx ip allocation...
IP="$(kubectl -n ingress-nginx get svc -o jsonpath="{.status.loadBalancer.ingress[0].ip}" ingress-nginx-controller)"
# apply workloads + runtimes
kubectl apply -f wasm.yaml
curl -v http://$IP/spin/hello
curl -v http://$IP/slight/hello
#!/usr/bin/env bash
az feature register --namespace "Microsoft.ContainerService" --name "WasmNodePoolPreview"
export GROUP=ace-waci2
export NAME=ace-waci2
export LOCATION=westcentralus # only region deployed with shims
az group create -g "${GROUP}" -l ${LOCATION}
# settings ace likes for cluster creation
az aks create -g $GROUP -n "${NAME}" -l $LOCATION --network-plugin azure --node-vm-size Standard_D4ads_v5 -c 2 -k 1.23.8 --network-plugin azure --vm-set-type VirtualMachineScaleSets --load-balancer-sku standard --node-osdisk-type Managed --node-osdisk-size 512
az aks get-credentials -g $GROUP -n $NAME
# juicy bits
az aks nodepool add -g "$GROUP" --cluster-name "$NAME" -n amd64wasm --node-osdisk-type Managed --node-osdisk-size 512 --node-vm-size Standard_D4ads_v5 -c 1 --workload-runtime WasmWasi
az aks nodepool add -g "$GROUP" --cluster-name "$NAME" -n arm64wasm --node-osdisk-type Managed --node-osdisk-size 512 --node-vm-size Standard_D4pds_v5 -c 1 --workload-runtime WasmWasi
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: "wasmtime-slight-v1"
handler: "slight"
scheduling:
nodeSelector:
"kubernetes.azure.com/wasmtime-slight-v1": "true"
---
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: "wasmtime-spin-v1"
handler: "spin"
scheduling:
nodeSelector:
"kubernetes.azure.com/wasmtime-spin-v1": "true"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wasm-slight
spec:
replicas: 1
selector:
matchLabels:
app: wasm-slight
template:
metadata:
labels:
app: wasm-slight
spec:
runtimeClassName: wasmtime-slight-v1
containers:
- name: testwasm
image: ghcr.io/deislabs/containerd-wasm-shims/examples/slight-rust-hello:latest
command: ["/"]
---
apiVersion: v1
kind: Service
metadata:
name: wasm-slight
spec:
ports:
- protocol: TCP
port: 80
targetPort: 80
selector:
app: wasm-slight
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wasm-spin
spec:
replicas: 3
selector:
matchLabels:
app: wasm-spin
template:
metadata:
labels:
app: wasm-spin
spec:
runtimeClassName: wasmtime-spin-v1
containers:
- name: testwasm
image: ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:latest
command: ["/"]
---
apiVersion: v1
kind: Service
metadata:
name: wasm-spin
spec:
ports:
- protocol: TCP
port: 80
targetPort: 80
selector:
app: wasm-spin
type: LoadBalancer
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wasm-ingress
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- path: /spin(/|$)(.*)
pathType: Prefix
backend:
service:
name: wasm-spin
port:
number: 80
- path: /slight(/|$)(.*)
pathType: Prefix
backend:
service:
name: wasm-slight
port:
number: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment