Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6b2d860

Browse files
authoredAug 5, 2024··
Added docs for Kubernetes+containerd+runwasi setup, updated runwasi setup page (#240)
Signed-off-by: Shivesh Gupta <shiveshanjaligupta@gmail.com>
1 parent 4312ae6 commit 6b2d860

File tree

2 files changed

+143
-4
lines changed

2 files changed

+143
-4
lines changed
 

‎docs/develop/deploy/cri-runtime/containerd.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ The containerd-shim [runwasi](https://github.com/containerd/runwasi/) project su
1919
3. Build and install the wasmedge-containerd-shim
2020

2121
```bash
22+
# Reference: https://github.com/containerd/runwasi/blob/main/CONTRIBUTING.md#setting-up-your-local-environment
2223
cd runwasi
24+
./scripts/setup-linux.sh
2325
make build-wasmedge
2426
INSTALL="sudo install" LN="sudo ln -sf" make install-wasmedge
2527
```

‎docs/develop/deploy/kubernetes/kubernetes-containerd-runwasi.md

+141-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,144 @@ sidebar_position: 3
44

55
# Kubernetes + Containerd + Runwasi
66

7-
<!-- prettier-ignore -->
8-
:::info
9-
Work in Progress
10-
:::
7+
## Quick start
8+
9+
The [GitHub repo](https://github.com/second-state/wasmedge-containers-examples/) contains scripts and GitHub Actions for running our example apps on Kubernetes + containerd + runwasi.
10+
11+
- Simple WebAssembly example [Quick start](https://github.com/second-state/wasmedge-containers-examples/blob/main/kubernetes_containerd/README.md) | [Github Actions](https://github.com/second-state/wasmedge-containers-examples/blob/main/.github/workflows/kubernetes-containerd.yml)
12+
- WebAssembly-based HTTP service [Quick start](https://github.com/second-state/wasmedge-containers-examples/blob/main/kubernetes_containerd/http_server/README.md) | [Github Actions](https://github.com/second-state/wasmedge-containers-examples/blob/main/.github/workflows/kubernetes-containerd-server.yml)
13+
14+
In the rest of this section, we will explain the steps in detail.
15+
16+
## Prerequisites for this setup
17+
18+
Please ensure that you have completed the following steps before proceeding with this setup.
19+
20+
- Install the latest version of [Wasmedge](../../../start/install.md)
21+
- Ensure that you have containerd setup following the [instructions here](../../deploy/cri-runtime/containerd-crun.md).
22+
- Ensure that you have installed and [setup runwasi](../../deploy/cri-runtime/containerd.md) for containerd-shim-wasmedge
23+
24+
25+
26+
## Install and start Kubernetes
27+
28+
Run the following commands from a terminal window. It sets up Kubernetes for local development.
29+
30+
```bash
31+
# Install go
32+
$ wget https://golang.org/dl/go1.17.1.linux-amd64.tar.gz
33+
$ sudo rm -rf /usr/local/go
34+
$ sudo tar -C /usr/local -xzf go1.17.1.linux-amd64.tar.gz
35+
$ source /home/${USER}/.profile
36+
37+
# Clone k8s
38+
$ git clone https://github.com/kubernetes/kubernetes.git
39+
$ cd kubernetes
40+
$ git checkout v1.22.2
41+
42+
# Install etcd with hack script in k8s
43+
$ sudo CGROUP_DRIVER=systemd CONTAINER_RUNTIME=remote CONTAINER_RUNTIME_ENDPOINT='unix:///var/run/containerd/containerd.sock' ./hack/install-etcd.sh
44+
$ export PATH="/home/${USER}/kubernetes/third_party/etcd:${PATH}"
45+
$ sudo cp third_party/etcd/etcd* /usr/local/bin/
46+
47+
# After run the above command, you can find the following files: /usr/local/bin/etcd /usr/local/bin/etcdctl /usr/local/bin/etcdutl
48+
49+
# Build and run k8s with containerd
50+
$ sudo apt-get install -y build-essential
51+
$ sudo CGROUP_DRIVER=systemd CONTAINER_RUNTIME=remote CONTAINER_RUNTIME_ENDPOINT='unix:///var/run/containerd/containerd.sock' ./hack/local-up-cluster.sh
52+
53+
... ...
54+
Local Kubernetes cluster is running. Press Ctrl-C to shut it down.
55+
```
56+
57+
Do NOT close your terminal window. Kubernetes is running!
58+
59+
60+
## Run and test the Kubernetes Cluster
61+
62+
Finally, we can run WebAssembly programs in Kubernetes as containers in pods. In this section, we will start from **another terminal window** and start using the cluster.
63+
64+
```bash
65+
export KUBERNETES_PROVIDER=local
66+
67+
sudo cluster/kubectl.sh config set-cluster local --server=https://localhost:6443 --certificate-authority=/var/run/kubernetes/server-ca.crt
68+
sudo cluster/kubectl.sh config set-credentials myself --client-key=/var/run/kubernetes/client-admin.key --client-certificate=/var/run/kubernetes/client-admin.crt
69+
sudo cluster/kubectl.sh config set-context local --cluster=local --user=myself
70+
sudo cluster/kubectl.sh config use-context local
71+
sudo cluster/kubectl.sh
72+
```
73+
74+
Let's check the status to make sure that the cluster is running.
75+
76+
```bash
77+
$ sudo cluster/kubectl.sh cluster-info
78+
79+
# Expected output
80+
Cluster "local" set.
81+
User "myself" set.
82+
Context "local" created.
83+
Switched to context "local".
84+
Kubernetes control plane is running at https://localhost:6443
85+
CoreDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
86+
87+
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
88+
```
89+
90+
## Configure containerd and Kubernetes for Wasmedge Runtime
91+
92+
Next we will configure containerd to add support for the containerd-shim-wasmedge.
93+
Please ensure that you have [setup runwasi](../../deploy/cri-runtime/containerd.md) to work with WasmEdge container images.
94+
```bash
95+
# Run the following command as root user
96+
sudo bash -c "containerd config default > /etc/containerd/config.toml"
97+
echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmedge] runtime_type = "io.containerd.wasmedge.v1"' | sudo tee -a /etc/containerd/config.toml > /dev/null
98+
sudo systemctl restart containerd
99+
```
100+
101+
Next we will create a RuntimeClass in Kubernetes to specify usage of wasmedge runtime for objects labeled as `runtime=wasm`
102+
103+
```bash
104+
sudo cluster/kubectl.sh apply -f - <<< '{"apiVersion":"node.k8s.io/v1","kind":"RuntimeClass","metadata":{"name":"wasm"},"scheduling":{"nodeSelector":{"runtime":"wasm"}},"handler":"wasmedge"}'
105+
```
106+
107+
Now we will label the kubernetes node as `runtime=wasm`. Note that the node where we changed the containerd configurations will be the one which we will label.
108+
109+
An example of how we can label the node is given below:
110+
111+
```bash
112+
sudo cluster/kubectl.sh get nodes
113+
# Sample output from the command above
114+
NAME STATUS ROLES AGE VERSION
115+
127.0.0.1 Ready <none> 3h4m v1.22.2
116+
# Run the following command to label the node
117+
sudo cluster/kubectl.sh label nodes 127.0.0.1 runtime=wasm
118+
# A successful output from the above command looks like this
119+
node/127.0.0.1 labeled
120+
```
121+
### A WebAssembly-based HTTP service
122+
123+
[A separate article](https://github.com/second-state/wasmedge-containers-examples/blob/main/http_server_wasi_app.md) explains how to compile, package, and publish a simple WebAssembly HTTP service application as a container image to Docker hub. Run the WebAssembly-based image from Docker Hub in the Kubernetes cluster as follows.
124+
125+
```bash
126+
sudo cluster/kubectl.sh apply -f - <<< '{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"http-server-deployment"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"http-server"}},"template":{"metadata":{"labels":{"app":"http-server"}},"spec":{"hostNetwork":true,"runtimeClassName":"wasm","containers":[{"name":"http-server","image":"wasmedge/example-wasi-http:latest","ports":[{"containerPort":1234}]}]}}}}'
127+
```
128+
129+
Since we are using `hostNetwork` in the `kubectl run` command, the HTTP server image is running on the local network with IP address `127.0.0.1`. Now, you can use the `curl` command to access the HTTP service.
130+
131+
```bash
132+
$ curl -d "name=WasmEdge" -X POST http://127.0.0.1:1234
133+
echo: name=WasmEdge
134+
```
135+
136+
That's it!
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+

0 commit comments

Comments
 (0)
Please sign in to comment.