Deploy OpenFaaS to Docker Swarm

A Foreword On Security

These instructions are for a development environment. If you plan to expose OpenFaaS on the public Internet you need to enable basic authentication with a proxy such as Kong or Traefik at a minimum.

TLS is also highly recomended and freely available from LetsEncrypt.org.

Refer to the Kong and Traefik Integration Guides for instructions on using them with OpenFaaS.

The deployment guide for Docker Swarm provides a simple one-line command to get you up and running in around 60 seconds.

If you already have a working Docker Swarm you can skip to the Deploy OpenFaaS section.

Create a Docker Swarm

You can create a single-host Docker Swarm on your laptop with a single command. You don't need any additional software to Docker 17.05 or greater. You can also run these commands on a Linux VM or cloud host running Docker.

Initialize Swarm Mode

  1. Initalise the Swarm master node with:

    # docker swarm init
    

    Multiple IP Addresses

    If you have more than one IP address you may need to explicitly set the interface the Swarm will advertise on using by adding --advertise-addr eth0 to the command above. Refer to the Docker CLI docs for more info.

  2. Take a note of the join token

Join Swarm Workers

  1. Log into your worker node(s) (if any) and type in the output from docker swarm init on the master.

    If you've lost this info then type in docker swarm join-token worker and then enter that on the worker.

    It's also important to pass the --advertise-addr string to any hosts which have a public IP address.

    Optional Firewall Updates

    Check whether you need to enable firewall rules for the Docker Swarm ports listed here.

Deploy OpenFaaS

  1. Clone the OpenFaaS repo and checkout the latest stable release:

    $ git clone https://github.com/openfaas/faas && \
      cd faas && \
      git checkout 0.6.7
    
  2. Deploy the OpenFaaS Stack (Linux/OSX)

    $ ./deploy_stack.sh
    

  3. Deploy the OpenFaaS Stack (Windows Powershell)

    $ ./deploy_stack.ps1
    

./deploy_stack.* scripts can be run at any time and include a set of sample functions.

Asynchronous OpenFaaS

The provided ./deploy_extended.sh script lets you deploy OpenFaaS with support for Asynchronous functions. Read more about using OpenFaaS with Async support here.

Connect to OpenFaaS

API Gateway

OpenFaaS should complete its deployment within a few seconds (or minutes if on a poor WiFi connection), the API gateway and sample functions will be pulled into your local Docker library and you will be able to access the UI at:

Localhost Times Out

If you're running on Linux you may find that localhost times out when IPv6 is enabled. In this case force an IPv4 address such as http://127.0.0.1:8080.

OpenFaaS API Gateway Dashboard

Prometheus

The Grafana dashboard linked to OpenFaaS will be accessible at:

Continue Getting Started

If you are following the Getting Started Guide you should proceed to Step 2 - OpenFaaS UIs.