FaaS QuickStart
1. Features
Layotto supports loading and running functions in the form of wasm, and supports calling each other between functions and accessing infrastructure, such as Redis.
Detailed design documents can refer to:FaaS design
2. Dependent software
The following software needs to be installed to run this demo:
-
Download the installation package from the official website and install it.
-
Follow the instructions on the official website.
-
Download the installation package from the official website and install it. You can also use homebrew to install it on mac. If the startup fails after installation, please refer to The host-only adapter we just created is not visible.
3. Setup
A、Install & run Redis
The example only needs a Redis server that can be used normally. As for where it is installed, there is no special restriction. It can be a virtual machine, a local machine or a server. Here, the installation on mac is used as an example to introduce.
> brew install redis
> redis-server /usr/local/etc/redis.conf
Note: If you want external services to connect to redis, you need to modify the protected-mode in redis.conf to no,At the same time, add bind * -:: to let it monitor all interfaces.*
B、Start minikube in virtualbox + containerd mode
> minikube start --driver=virtualbox --container-runtime=containerd
C、Compile & install Layotto
> git clone https://github.com/mosn/layotto.git
> cd layotto
> make wasm-build
> minikube cp ./_output/linux/amd64/layotto /home/docker/layotto
> minikube cp ./demo/faas/config.json /home/docker/config.json
> minikube ssh
> sudo chmod +x layotto
> sudo mv layotto /usr/bin/
Note1: You need to modify the redis address as needed, the default address is: localhost:6379
Note2: Need to modify the path of the wasm file in ./demo/faas/config.json
to /home/docker/function_1.wasm
and /home/docker/function_2.wasm
Note3: We can also load WASM file dynamically. For details, see WASM Dynamic Load
D、Compile & install containerd-shim-layotto-v2
> git clone https://github.com/layotto/containerd-wasm.git
> cd containerd-wasm
> sh build.sh
> minikube cp containerd-shim-layotto-v2 /home/docker/containerd-shim-layotto-v2
> minikube ssh
> sudo chmod +x containerd-shim-layotto-v2
> sudo mv containerd-shim-layotto-v2 /usr/bin/
E、Modify & restart containerd
Add laytto runtime configuration.
> minikube ssh
> sudo vi /etc/containerd/config.toml
[plugins.cri.containerd.runtimes.layotto]
runtime_type = "io.containerd.layotto.v2"
Restart containerd for the latest configuration to take effect
sudo systemctl restart containerd
F、Install wasmer (If the vm engine uses wasmer, you need to execute the following command)
> curl -L -O https://github.com/wasmerio/wasmer/releases/download/2.0.0/wasmer-linux-amd64.tar.gz
> tar zxvf wasmer-linux-amd64.tar.gz
> sudo cp lib/libwasmer.so /usr/lib/libwasmer.so
4. Quickstart
A、Start Layotto
> minikube ssh
> layotto start -c /home/docker/config.json
B、Create Layotto runtime
> kubectl apply -f ./demo/faas/layotto-runtimeclass.yaml
runtimeclass.node.k8s.io/layotto created
C、Create Function
This operation will automatically inject function_1.wasm and function_2.wasm into the Virtualbox virtual machine.
> kubectl apply -f ./demo/faas/function-1.yaml
pod/function-1 created
> kubectl apply -f ./demo/faas/function-2.yaml
pod/function-2 created
D、Write inventory to Redis
> redis-cli
127.0.0.1:6379> set book1 100
OK