Install OpenFaaS
Run individual functions as services on your own machine, all the way from an empty folder to an address that responds, with the license terms printed first.
Last reviewed:
What OpenFaaS is
A way to run a single function as a service. You write a short piece of code that does one thing, for example calculating shipping or receiving a form, and OpenFaaS makes it available at a web address. No server to configure, no web framework to learn first.
The word for it is serverless, which is misleading, because the server is still there. The difference is that you stop thinking about it.
Read the license terms before you start, they are unusual
This is the only guide in the collection where the license can stop you, so it comes first instead of last.
The free version is called faasd CE and, according to the publisher's own terms, is intended for personal and non-commercial use, with up to 15 functions. There is a 60-day evaluation period for anyone who wants to try it in a commercial setting. A company that sells a product is a commercial setting, even if revenue is small.
The commercial version is called OpenFaaS Edge and costs money. What it costs right now is on the publisher's site at openfaas.com, and you can read it there because prices change more often than this guide.
The conclusion is simple. If you want to learn how serverless functions work, run faasd CE. If you are going to build something that is part of what you sell in your business, choose something else or buy the license. Do not mix up the two.
Linux Mint
OpenFaaS runs on Linux. Open Terminal and run the three commands in order:
sudo apt-get install git
git clone https://github.com/openfaas/faasd --depth=1
cd faasd && sudo ./hack/install.sh
The first line installs git, the program that fetches code from the internet. Mint does not come with it, and the second line does not work without it.
The installation takes a few minutes. When it is done, it prints the commands you should run next, including the password for the interface. If you cannot find the output, you can get the password again with:
sudo cat /var/lib/faasd/secrets/basic-auth-password
The interface is then at http://localhost:8080, and the username is admin.
Windows
There is no installation directly on Windows. You need a Linux system, and the simplest is WSL2, which is Windows' own built-in Linux. Open PowerShell as administrator and run:
wsl --install -d Ubuntu
Restart the computer, open Ubuntu from the start menu, and then run exactly the same three commands as under Linux Mint above. You stay in Windows the whole time, the terminal window is just a Linux system inside it.
Three things to do first
- Install the command line tool
faas-cli, because that is what you actually work with. One line is enough:curl -sSL https://cli.openfaas.com | sudo sh. Then log in with the password you just retrieved:faas-cli login --password DITT_LOSENORD. - Create your first function instead of looking for a ready-made file. Run
faas-cli new --lang python3 --prefix docker.io/ert-dockerhub-namn hej. That creates the folderhejwith the code, and the filehej.ymlnext to it. The file does not exist before you create it, and that is where most guides skip a step. - Unlike faas-cli, faasd has no Docker built in, and
faas-cli upbuilds the image with Docker and then pulls it from an image registry, not locally. So install Docker according to Install Docker if you have not already done so, and create a free account on hub.docker.com to use as a registry. Log in withdocker loginand build, push and deploy the function in one go withfaas-cli up -f hej.yml. Then call it withcurl http://localhost:8080/function/hej. Now you have gone all the way from an empty folder to a working address, and the rest is variations on that.
The most common trap
Running faas-cli deploy on a file that does not exist. The command deploy deploys a function that is already built, while up does the build and the deploy in one go. If you start with deploy before you have run new and build, you get an error message saying the file is missing, and it is easy to read that as the installation being broken. It is not. It is the order that is wrong.
Use up until you have a reason to split the steps. Then it does not happen.