Installing OpenFaaS

It is extremely simple to install OpenFaaS locally on a development machine. Make sure you have Docker 17.05 or later installed and you will be ready to go.

First, we need to initialize a Swarm cluster. A single node Swarm is enough to be used in the development environment:

$ docker swarm init
If the Swarm cannot be initialized because the machine has multiple network interfaces, we have to specify an IP address or an interface name for the argument, --advertise-addr.

OpenFaaS can be up and running directly from its source by cloning the repository from GitHub. Then, check out the OpenFaaS version you want and run the deploy_stack.sh script. The following example is to start version 0.6.5 of OpenFaaS. Please note that there is docker-compose.yml in this directory, which will be used by the docker_stack.sh to deploy the OpenFaaS Docker stack:

$ git clone https://github.com/openfaas/faas 
cd faas
git checkout 0.6.5
./deploy_stack.sh
Cloning into 'faas'...
remote: Counting objects: 11513, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 11513 (delta 16), reused 19 (delta 8), pack-reused 11484
Receiving objects: 100% (11513/11513), 16.64 MiB | 938.00 KiB/s, done.
Resolving deltas: 100% (3303/3303), done.
Note: checking out '0.6.5'.
HEAD is now at 5a58db2...

Deploying stack
Creating network func_functions
Creating service func_gateway
Creating service func_alertmanager
Creating service func_echoit
Creating service func_nodeinfo
Creating service func_wordcount
Creating service func_webhookstash
Creating service func_decodebase64
Creating service func_markdown
Creating service func_base64
Creating service func_hubstats
Creating service func_prometheus

We now see that a number of services are deployed to the Docker Swarm cluster. It is actually done by running docker stack deploy behind the scenes inside the bash script. The Docker stack's name used by OpenFaaS is func

To check whether services are deployed properly in the func stack, we use docker stack ls to list stacks and their running services:

$ docker stack ls
NAME SERVICES
func 11

Now we know that there is a stack of 11 services named func. Let's check their details with docker stack services func. We use the format argument to let the docker stack services func command show each service's name and port. You can leave out the --format to see all information about each service:

$ docker stack services func --format "table {{.Name}}	{{.Ports}}"
NAME PORTS
func_hubstats
func_markdown
func_echoit
func_webhookstash
func_prometheus *:9090->9090/tcp
func_gateway *:8080->8080/tcp
func_decodebase64
func_base64
func_wordcount
func_alertmanager *:9093->9093/tcp
func_nodeinfo

After everything is up and running, the OpenFaaS portal can be opened via http://127.0.0.1:8080. The following screenshot shows the browser running OpenFaaS Portal. All available functions are listed in the left panel. When clicking a function name, the main panel will show the function's details. We can play around with each function by clicking the INVOKE button on the main panel:

Figure 4.5: The OpenFaaS UI invoking an example function

We will learn how to prepare a function to run on the OpenFaaS platform in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset