We can deploy Spin applications on Kubernetes using a Wasm containerd shim.
Before you begin, you need to have the following installed:
- Docker version 4.13.1 (90346) or later with containerd enabled
- k3d
- kubectl
- Spin binary and templates
- Rust
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.5.1 -p "8081:80@loadbalancer" --agents 2Apply RuntimeClass for spin applications to use the Spin containerd Wasm shim:
cat <<EOF | kubectl create -f -
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: wasmtime-spin
handler: spin
EOFWe will use an experimental Spin k8s plugin to package our Spin application inside a Container. While Spin supports packaging Spin applications as OCI artifacts with spin registry, currently, the containerd-wasm-shim expects the Wasm modules to be inside a container. The shim then pulls the module outside of the container when the application is deployed to the cluster. In the future, the shim may support Spin application OCI artifacts, reducing the steps needed to deploy your Spin application to a cluster.
The plugin requires that all modules are available locally and that files are within subdirectories of the working directory. In particular, we need to get the static fileserver module, move our frontend files within this directory, and update our component manifest with the new resource paths.
Install the plugin, scaffold the Dockerfile, build the container, and push it to your container registry. The following example uses the GitHub Container Registry.
Note: if creating a Rust app, before deploying the app to Kubernetes, modify the
spin.tomlfile to remove the following as the shim does not yet supportspin watch:watch = ["src/**/*.rs", "Cargo.toml"]
# Install the plugin
$ spin plugin install -y -u https://raw.githubusercontent.com/chrismatteson/spin-plugin-k8s/main/k8s.json
# Build your app locally
$ spin build
# Scaffold your Dockerfile, passing in the namespace of your registry
$ spin k8s scaffold ghcr.io/my-registry && spin k8s build
# Import your image into the k3d cluster
$ k3d image import -c wasm-cluster ghcr.io/my-registry/hello-typescript:0.1.0
# After making sure it is a publicly accessible container or adding a regcred to your `deploy.yaml`
$ spin k8s deploy
# Watch the applications become ready
$ kubectl get pods --watch
# Query the application (modify the endpoint path to match your application name)
$ curl -v http://0.0.0.0:8081/hello-typescriptTo learn more about each of the
k8splugin steps, see the documentation on running Spin on Kubernetes.
Bring down your k3d cluster:
k3d cluster delete wasm-clusterIn this section you learned how to:
- Use the containerd Wasm shim to package a Spin app within a Docker container
- Deploy a containerized Spin app to a Kubernetes cluster
- Go back to 2. Getting started with Spin if you still have questions on previous section
- (optionally) If finished, let us know what you thought of the Spin and the workshop with this short Typeform survey.