OpenFaaS on DCOS
Serverless is regarded by many as THE innovative programming paradigm for the near future. In Wikipedia words, serverless is a “cloud computing execution model” where the developer just writes some code, but he or she doesn’t have to care about provision or scaling issues.
In the serverless universe, OpenFaaS (https://www.openfaas.com) is one of the most interesting open source projects. OpenFaas is not tied to any particular cloud provider or vendor and you can also run it on-premises.
If you want to go deeper on serverless subject, you can read Alex blog post https://blog.alexellis.io/introducing-functions-as-a-service (Alex is original OpenFaaS author).
Serverless code will as always run on some server under the hood. But OpenFaaS will run on many orchestrators such as Docker Swarm, Kubernetes and now DCOS (https://dcos.io/).
DCOS cluster installation
Let’s go through a step-by-step installation of DCOS and OpenFaaS.
DCOS installation is very well documented on Mesosphere site (https://dcos.io/install) and you have many options: local, cloud or on-premises. For our demo, we’ll install it locally using Vagrant.
Just follow the instructions here https://github.com/dcos/dcos-vagrant, but before executing
vagrant up, you need to add the line
at the end of dcos-vagrant/etc/config-1.10.yaml file to disable authentication.
Once Vagrant has finished doing its things, DCOS cluster should be available and you should be able to access its dashboard at http://m1.dcos/
Vagrant was kind enough to configure some local alias: m1.dcos for master node and p1.dcos for the public node.
Now we can install the load balancer service on the public node in order to expose functions to the outside world. Marathon-LB can be easily installed from DCOS Catalog packages (if you cannot find it just type “marathon” in the search field)
The default configuration is okay, just click on REVIEW&RUN and then RUN SERVICE buttons. After a few minutes, under Services you will find the balancer running.
Okay, we’re almost done. We now need to install DCOS CLI, the command line utility to control the cluster. The easiest way is to follow instructions you can find on the Dashboard itself. In the upper left corner there is a combo-box, click on that and a menu will appear.
Click on “Install CLI” and a dialog will be shown with instructions for different OS flavors.
Alright, well done! If you now execute the command
dcos node for instance, you should see something like this:
% dcos node
HOSTNAME IP ID TYPE
192.168.65.111 192.168.65.111 9b1c4a7f-0e65-429c-9d7a-416397475ca8-S3 agent
192.168.65.60 192.168.65.60 9b1c4a7f-0e65-429c-9d7a-416397475ca8-S2 agent
master.mesos. 192.168.65.90 9b1c4a7f-0e65-429c-9d7a-416397475ca8 master (leader)
Now we’re finally ready to install OpenFaaS on DCOS.
Clone the repository https://github.com/realbot/faas-dcos and from that directory execute the command:
dcos marathon group add faas-dcos.json
In the Service window, you should see OpenFaaS being deployed
and if, hopefully, everything works fine, you should have a green bar at the end
OpenFaaS GUI interface is now be available at http://p1.dcos:10012/ui/
where you can start playing with functions. You can install them manually or automatically from the brand new store, where many useful functions are available and deployable with just one click.
Alternatively a CLI is also supported (https://github.com/openfaas/faas-cli) to manage OpenFaaS, but remember to make it point to the right gateway using either the
in the yaml file or the
faas-cli ...--gateway=http://m1.dcos:10012 ..
on the command line.
Support for cluster authentication is something that will be added in future releases and, of course, if you want to help with this project PR are always very welcome.
Virtually every program or script that takes an input and produce an output can be converted into a function. Many language are supported (even a bash script!) and here you will find lots of ready-to-be-used templates.
I hope this brief introduction to serverless and OpenFaaS will help to get you involved, try to build a function today!
Written by Alberto Quario