Skip to content

Latest commit

 

History

History
277 lines (236 loc) · 7.23 KB

File metadata and controls

277 lines (236 loc) · 7.23 KB

Quickstart

Pre-requisites

Before you begin, you need to have the following installed:

Start and configure a k3d cluster

Start a k3d cluster with the WASM shims already installed:

k3d cluster create wasm-cluster --image ghcr.io/deislabs/containerd-wasm-shims/examples/k3d:v0.3.3 -p "8081:80@loadbalancer" --agents 2 --registry-create mycluster-registry:12345

Apply RuntimeClass for Wasm Workers Server applications to use the wws Wasm shim:

kubectl apply -f https://raw.githubusercontent.com/deislabs/containerd-wasm-shims/main/deployments/workloads/runtime.yaml

Deploy an existing sample Wasm Workers Server application

Deploy a pre-built sample wws application:

kubectl apply -f https://raw.githubusercontent.com/deislabs/containerd-wasm-shims/main/deployments/workloads/workload.yaml
echo "waiting 5 seconds for workload to be ready"
sleep 5
curl -v http://0.0.0.0:8081/wws/hello

Confirm you see a response from the sample application. For example:

$ curl -v http://0.0.0.0:8081/wws/hello
*   Trying 0.0.0.0:8081...
* TCP_NODELAY set
* Connected to 0.0.0.0 (127.0.0.1) port 8081 (#0)
> GET /hello HTTP/1.1
> Host: 0.0.0.0:8081
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept: */*
< Accept-Encoding: gzip
< Content-Length: 5
< Date: Tue, 11 Oct 2022 19:12:17 GMT
< Host: 0.0.0.0:8081
< User-Agent: curl/7.68.0
< X-Forwarded-For: 10.42.1.1
< X-Forwarded-Host: 0.0.0.0:8081
< X-Forwarded-Port: 8081
< X-Forwarded-Proto: http
< X-Forwarded-Server: traefik-7cd4fcff68-xr2gh
< X-Real-Ip: 10.42.1.1
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host 0.0.0.0 left intact
<!DOCTYPE html>
<head>
  <title>Wasm Workers Server</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta charset="UTF-8">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
  <style>
    body { max-width: 1000px; }
    main { margin: 5rem 0; }
    h1, p { text-align: center; }
    h1 { margin-bottom: 2rem; }
    pre { font-size: .9rem; }
    pre > code { padding: 2rem; }
    p { margin-top: 2rem; }
  </style>
</head>
<body>
  <main>
    <h1>Hello from Wasm Workers Server 👋</h1>
    <pre><code>Replying to /hello
Method: GET
User Agent: undefined
Payload: -</code></pre>
    <p>
      This page was generated by a JavaScript file running in WebAssembly.
    </p>
  </main>
</body>

This example is a website, so feel free to check it on your browser by accessing http://0.0.0.0:8081/wws/hello.

Delete the pre-built sample Wasm Workers Server application:

kubectl delete -f https://raw.githubusercontent.com/deislabs/containerd-wasm-shims/main/deployments/workloads/workload.yaml

Build and deploy a Wasm Workers Server application

Clone the deislabs/containerd-wasm-shims project and navigate to the containerd-wasm-shims/images/wws directory. This directory contains the source for the application you deployed in the previous section.

Note that Wasm Workers Server only requires the source code file for languages like JavaScript. You have more information about how it works in the documentation.

git clone https://github.com/deislabs/containerd-wasm-shims.git
cd containerd-wasm-shims/images/wws

Run the application

Use wws to run the application on your development computer. For example:

wws .

The application is running at http://localhost:8080/hello.

Return to the terminal window running wws and stop the application.

Create a container image for the application

Use docker to build the container image and push it to the k3d registry:

docker buildx build --platform=wasi/wasm -t localhost:12345/qs-wasm-wws .
docker push localhost:12345/qs-wasm-wws:latest

Deploy the application

Create a qs.yaml file with the following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wasm-wws
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wasm-wws
  template:
    metadata:
      labels:
        app: wasm-wws
    spec:
      runtimeClassName: wasmtime-wws
      containers:
        - name: testwasm
          image: mycluster-registry:12345/qs-wasm-wws:latest
          command: ["/"]
---
apiVersion: v1
kind: Service
metadata:
  name: wasm-wws
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
  selector:
    app: wasm-wws
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wasm-wws
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  ingressClassName: traefik
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: wasm-wws
                port:
                  number: 80

Deploy the application and confirm it is running:

kubectl apply -f qs.yaml
echo "waiting 5 seconds for workload to be ready"
sleep 5
curl -v http://0.0.0.0:8081/hello

Confirm you see a response from the sample application. For example:

$ curl -v http://0.0.0.0:8081/hello
*   Trying 0.0.0.0:8081...
* TCP_NODELAY set
* Connected to 0.0.0.0 (127.0.0.1) port 8081 (#0)
> GET /hello HTTP/1.1
> Host: 0.0.0.0:8081
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept: */*
< Accept-Encoding: gzip
< Content-Length: 5
< Date: Tue, 11 Oct 2022 20:29:12 GMT
< Host: 0.0.0.0:8081
< User-Agent: curl/7.68.0
< X-Forwarded-For: 10.42.0.0
< X-Forwarded-Host: 0.0.0.0:8081
< X-Forwarded-Port: 8081
< X-Forwarded-Proto: http
< X-Forwarded-Server: traefik-7cd4fcff68-xr2gh
< X-Real-Ip: 10.42.0.0
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host 0.0.0.0 left intact
<!DOCTYPE html>
<head>
  <title>Wasm Workers Server</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta charset="UTF-8">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
  <style>
    body { max-width: 1000px; }
    main { margin: 5rem 0; }
    h1, p { text-align: center; }
    h1 { margin-bottom: 2rem; }
    pre { font-size: .9rem; }
    pre > code { padding: 2rem; }
    p { margin-top: 2rem; }
  </style>
</head>
<body>
  <main>
    <h1>Hello from Wasm Workers Server 👋</h1>
    <pre><code>Replying to /hello
Method: GET
User Agent: undefined
Payload: -</code></pre>
    <p>
      This page was generated by a JavaScript file running in WebAssembly.
    </p>
  </main>
</body>

Clean up

Remove the sample application:

kubectl delete -f qs.yaml

Delete the cluster:

k3d cluster delete wasm-cluster

Next steps

Try running Wasm applications on Docker Desktop or on Kubernetes, such as AKS.