Overview
Getting Started
Install knative and WASMEdge on IBM Cloud
-
Create a cluster called
knawd-k8s
on IBM Cloud. For full instructions see https://cloud.ibm.com/docs/containers?topic=containers-getting-started -
Install the IBM Cloud Cli. The instructions please ensure you install the https://cloud.ibm.com/docs/cli?topic=cli-getting-started
-
Install the kubernetes service plugin https://cloud.ibm.com/docs/cli?topic=cli-install-devtools-manually#idt-install-kube
-
Once the cluster is complete login with the ibmcloud cli
ibm cloud login
-
Now configure the kubectl connection
ibmcloud ks cluster config -c knawd-k8s
-
We are going to follow a summary of the instructions for the knative website.
-
Install the custom resource definitions which are the objects such as
service
that you will use to deploy an app.kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.8.3/serving-crds.yaml
-
Then install the knative serving core
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.8.3/serving-core.yaml
-
Now we install the networking layer
kubectl apply -f https://github.com/knative/net-kourier/releases/download/knative-v1.8.1/kourier.yaml
-
And Patch the knative space
kubectl patch configmap/config-network \ --namespace knative-serving \ --type merge \ --patch '{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}'
-
Finally configure dns
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.8.3/serving-default-domain.yaml
-
Patch the knative service to allow for the crun runtime to be specified as an attribute in the service.
kubectl patch configmap/config-features -n knative-serving --type merge --patch '{"data":{"kubernetes.podspec-runtimeclassname":"enabled"}}'
-
Now run install the deployment project
git clone https://github.com/uirlis/wasi-crun-deployer cd wasi-crun-deployer/charts/wasi-crun-deployer helm install wasi-crun-deployer . --create-namespace --namespace knawd --set job.autoRestart=true
-
Finally run the tempate helloworld service.
git clone https://github.com/uirlis/helloworld-rust-wasi cd helloworld-rust-wasi kubectl apply -f service.yaml
-
Get the external IP of the kourier network
kubectl get svc kourier -n kourier-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kourier LoadBalancer 172.21.191.127 159.122.80.147 80:32294/TCP,443:31406/TCP 44m
-
Visit the endpoint generated buy sslip.io - http://helloworld-rust-wasi.default.
.sslip.io/ curl http://helloworld-rust-wasi.default.159.122.80.147.sslip.io/ Hello Rust Sample v1
Install knative and WASMEdge on OpenShift
WIP - This is a first draft and NOT had a clean cluster validation.
-
Follow the excellent OpenShift documentation to install OpenShift Serverless which is based on knative. Ensure that you also install the knative-serving service into the
knative-serving
projecthttps://docs.openshift.com/container-platform/4.11/serverless/install/install-serverless-operator.html
-
Patch the knative service to allow for the crun runtime to be specified as an attribute in the service.
oc patch configmap/config-features -n knative-serving --type merge --patch '{"data":{"kubernetes.podspec-runtimeclassname":"enabled"}}'
-
As the deployer configures the node it needs to run with elevated privaliges. We should create a dedicated project for it and apply labels to minimise the warnings returned.
oc new-project knawd oc label --overwrite ns knawd pod-security.kubernetes.io/enforce=privileged pod-security.kubernetes.io/enforce-version=v1.24 oc label --overwrite ns knawd pod-security.kubernetes.io/audit=privileged pod-security.kubernetes.io/enforce-version=v1.24 oc label --overwrite ns knawd pod-security.kubernetes.io/warn=privileged pod-security.kubernetes.io/enforce-version=v1.24
This should be part of the helm package in later releases.
-
Now run install the project into the
knawd
on the clustergit clone https://github.com/uirlis/wasi-crun-deployer cd wasi-crun-deployer/charts/wasi-crun-deployer helm install wasi-crun-deployer . --namespace knawd -f rhel8-values.yaml --set job.autoRestart=true
-
Finally run the sample helloworld service to validate the installation.
git clone https://github.com/uirlis/helloworld-rust-wasi cd helloworld-rust-wasi kubectl apply -f service.yaml
Develop a WASMEdge Service in Rust
Before you start please ensure that you have run through the getting started section to create an WASMEdge enabled kubernetes environment.
In this section we are going to build a very simple service that highlights the key aspects for running a WASM service on Knative.
We assume you have a running rust environment. If not please goto rustup.
We also assume you have a container management system such as docker or podman installed.
-
Install
cargo generate
This is a templating engine that can parse git repos to create projects.cargo install generate
-
Install
cargo wasi
withcargo install cargo-wasi
-
Set
CARGO_TARGET_WASM32_WASI_RUNNER=wasmedge
in your.profile
or your user profile settings on Windows by clicking: System > Advanced system settings > Advanced > Environment Variables. -
Now generate a project. The template projects are standard Rust projects with place holders that replace the name of the project and and the repo configs.
cargo generate gh:knawd/gen-templates
The prompts help complete some of the assets in the project and map as follows:
-
The name of the project. This is used to give the cargo project a name and to fill out the service and build scripts for this project
-
"Want to create a knative service definition?" This is a yes/no response and if you respond with yes a knative service yaml will be created that enables you to push to your kuberenetes environment from your desktop.
-
"Which container registry would you like to use?" This is a freeform response that fills out the service file and the generated documentation. Usual responses
docker.io
orquay.io
-
"Which container organisation would you like to use?" This is a freeform response that fills out the service file and the generated documentation. Example organisation on is
knawd
available here - https://quay.io/organization/knawd
-
-
Once the project is created you can explore the
README.md
to understand the different options available to you. -
Let run the tests to make sure the projects has generated correctly. The tests are embedded at the bottom of the the
handler.rs
file. This is a convention in rust but they can be created in seperate files.cargo wasi test
-
Now look under the build section in the README.md. You will see a generated command to build the docker image. Run the command for
podman
ordocker
. i.e.docker build -t {{container_reg}}/{{container_org}}/{{project-name}} .
or
podman build -t {{container_reg}}/{{container_org}}/{{project-name}} .
-
Then in the push section of the README take the code snippets to push the application to your registry. i.e.
docker push {{container_reg}}/{{container_org}}/{{project-name}}
or
podman push {{container_reg}}/{{container_org}}/{{project-name}}
-
Finally you can deploy your knative service by applying the service to the kubernetes cluster using the deploy step in the Project README. i.e.
kubectl apply -f service.yaml
or
oc apply -f service.yaml