faasd - serverless with containerd

faasd is a Golang supervisor that bundles OpenFaaS for use with containerd instead of a container orchestrator like Kubernetes or Docker Swarm.
About faasd:
- faasd is a single Golang binary
- faasd is multi-arch, so works on
x86_64, armhf and arm64
- faasd downloads, starts and supervises the core components to run OpenFaaS
What does faasd deploy?
You can use the standard faas-cli with faasd along with pre-packaged functions in the Function Store, or build your own with the template store.
faas-containerd supports:
faas list
faas describe
faas deploy --update=true --replace=false
faas invoke
faas invoke --async
Other operations are pending development in the provider.
Pre-reqs
-
Linux
PC / Cloud - any Linux that containerd works on should be fair game, but faasd is tested with Ubuntu 18.04
For Raspberry Pi Raspbian Stretch or newer also works fine
For MacOS users try multipass.run or Vagrant
For Windows users, install Git Bash along with multipass or vagrant. You can also use WSL1 or WSL2 which provides a Linux environment.
-
Installation steps as per faas-containerd for building and for development
-
faas-cli (optional)
Backlog
Pending:
- Monitor and restart any of the core components at runtime if the container stops
- Bundle/package/automate installation of containerd - see bootstrap from k3s
- Provide ufw rules / example for blocking access to everything but a reverse proxy to the gateway container
- Provide simple Caddyfile example in the README showing how to expose the faasd proxy on port 80/443 with TLS
Done:
- Inject / manage IPs between core components for service to service communication - i.e. so Prometheus can scrape the OpenFaaS gateway - done via
/etc/hosts mount
- Add queue-worker and NATS
- Create faasd.service and faas-containerd.service
- Self-install / create systemd service via
faasd install
- Restart containers upon restart of faasd
- Clear / remove containers and tasks with SIGTERM / SIGINT
- Determine armhf/arm64 containers to run for gateway
- Configure
basic_auth to protect the OpenFaaS gateway and faas-containerd HTTP API
- Setup custom working directory for faasd
/run/faasd/
- Use CNI to create network namespaces and adapters
Tutorial: Get started on armhf / Raspberry Pi
You can run this tutorial on your Raspberry Pi, or adapt the steps for a regular Linux VM/VPS host.
Either download binaries
# For x86_64
sudo curl -fSLs "https://github.com/alexellis/faasd/releases/download/0.4.4/faasd" \
-o "/usr/local/bin/faasd" \
&& sudo chmod a+x "/usr/local/bin/faasd"
# armhf
sudo curl -fSLs "https://github.com/alexellis/faasd/releases/download/0.4.4/faasd-armhf" \
-o "/usr/local/bin/faasd" \
&& sudo chmod a+x "/usr/local/bin/faasd"
# arm64
sudo curl -fSLs "https://github.com/alexellis/faasd/releases/download/0.4.4/faasd-arm64" \
-o "/usr/local/bin/faasd" \
&& sudo chmod a+x "/usr/local/bin/faasd"
Or for hacking, you can build from source
Install the CNI plugins:
export CNI_VERSION=v0.8.4
- For PC run
export ARCH=amd64
- For RPi/armhf run
export ARCH=arm
- For arm64 run
export ARCH=arm64
Then run:
mkdir -p /opt/cni/bin
curl -sSL https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz | tar -xz -C /opt/cni/bin
First run faas-containerd
cd $GOPATH/src/github.com/alexellis/faas-containerd
# You'll need to install containerd and its pre-reqs first
# https://github.com/alexellis/faas-containerd/
sudo ./faas-containerd
Then run faasd, which brings up the gateway and Prometheus as containers
cd $GOPATH/src/github.com/alexellis/faasd
go build
# Install with systemd
sudo ./faasd install
Now you can access faasd on localhost:8080.
For development do not run faasd up manually unless you are working in development.
sudo ./faasd install --prepare # Only creates secrets, skipping systemd configuration
sudo cp -r /run/faasd/secrets . # Copy in generated secrets
sudo ./faasd up
At run-time
Look in hosts in the current working folder or in /run/faasd/ to get the IP for the gateway or Prometheus
127.0.0.1 localhost
10.62.0.1 faas-containerd
10.62.0.2 prometheus
10.62.0.3 gateway
10.62.0.4 nats
10.62.0.5 queue-worker
The IP addresses are dynamic and may change on every launch.
Since faas-containerd uses containerd heavily it is not running as a container, but as a stand-alone process. Its port is available via the bridge interface, i.e. openfaas0.
-
Prometheus will run on the Prometheus IP plus port 8080 i.e. http://[prometheus_ip]:9090/targets
-
faas-containerd runs on 10.62.0.1:8081
-
Now go to the gateway's IP address as shown above on port 8080, i.e. http://[gateway_ip]:8080 - you can also use this address to deploy OpenFaaS Functions via the faas-cli.
-
basic-auth
You will then need to get the basic-auth password, it is written to /run/faasd/secrets/basic-auth-password if you followed the above instructions.
The default Basic Auth username is admin, which is written to /run/faasd/secrets/basic-auth-user, if you wish to use a non-standard user then create this file and add your username (no newlines or other characters)
Installation with systemd
faasd install - install faasd and containerd with systemd, this must be run from $GOPATH/src/github.com/alexellis/faasd
journalctl -u faasd - faasd systemd logs
journalctl -u faas-containerd - faas-containerd systemd logs
Appendix
Links
https://github.com/renatofq/ctrofb/blob/31968e4b4893f3603e9998f21933c4131523bb5d/cmd/network.go
https://github.com/renatofq/catraia/blob/c4f62c86bddbfadbead38cd2bfe6d920fba26dce/catraia-net/network.go
https://github.com/containernetworking/plugins
https://github.com/containerd/go-cni