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
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.
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.*
> minikube start --driver=virtualbox --container-runtime=containerd
> git clone https://github.com/mosn/layotto.git
> cd layotto
> make wasm
> minikube cp ./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
> 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/
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
> 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
> minikube ssh
> layotto start -c /home/docker/config.json
> kubectl apply -f ./demo/faas/layotto-runtimeclass.yaml
runtimeclass.node.k8s.io/layotto created
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
> redis-cli
127.0.0.1:6379> set book1 100
OK
> minikube ip
192.168.99.117
> curl -H 'id:id_1' '192.168.99.117:2045?name=book1'
There are 100 inventories for book1.
- send http request to func1
- func1 calls func2 through Runtime ABI
- func2 calls redis through Runtime ABI
- Return results
-
Virtualbox failed to start, "The host-only adapter we just created is not visible":
-
When Layotto is started, the redis connection fails, and "occurs an error: redis store: error connecting to redis at" is printed:
Check the redis configuration to see if it is caused by a redis configuration error.
The FaaS model is currently in the POC stage, and the features are not complete. It will be improved in the following aspects in the future:
- Limit the maximum resources that can be used when the function is running, such as cpu, heap, stack, etc.
- The functions loaded and run by different Layotto can call each other.
- Fully integrate into the k8s ecology, such as reporting the use of resources to k8s, so that k8s can perform better scheduling.
- Add more Runtime ABI.
If you are interested in FaaS or have any questions or ideas, please leave a message in the issue area, we can build FaaS together!