Flynn is described by the makers as "an open source platform (PaaS) for running applications in production. It does everything you need, out of the box [including]creates running applications directly from your code so there's no need to learn configuration management or build custom stacks for each app, routes and load balances traffic to every instance of each of your apps, includes built-in Postgres, MySQL, and MongoDB databases with safe, automatic high availability, connects all your microservices with built-in service discovery".

We love Flynn! We're hoping to offer a PaaS to our customers soon and while Flynn doesn't have any protection or isolation between tenants, it's a really useful stack for running your own applications on using our cloud instances.

Launching

Flynn's minimum recommended requirements are "a clean Ubuntu installation on machines with at least 2GB of RAM, 40GB of storage, and two CPU cores each. It’s possible to run Flynn on servers with lower specs, but we don’t recommend it". They also recommend running at least 3 nodes. You can run it on a single node, but if that node goes down so does your application.

So let's launch 3 Small instances - they meet the requirements (2GB RAM, 2 Cores, 50GB storage) called flynn[1-3].civo.com (although obviously you'd use your own domain name).

flynn-instances.png

Firewalling

From bitter experience I've learnt to firewall these things early! You could use Civo's Firewalls for this but as we have a set of rules handy for Ubuntu's UFW, we'll use those. SSH into each instance and run the following:

sed -i -e 's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/' /etc/default/ufw
ufw allow ssh
ufw allow 80/tcp
ufw allow 443/tcp
ufw default deny incoming
ufw default allow outgoing
ufw allow from 10.0.0.73 # The internal IP of
ufw allow from 10.0.0.74 # all three instances
ufw allow from 10.0.0.75 # goes here
ufw allow in on flynnbr0
ufw allow in on flannel.1
ufw enable

Installing the Flynn host and installer software

On all three hosts we're going to run a single command to install the flynn-host installation and hosting script and run it:

sudo bash < <(curl -fsSL https://dl.flynn.io/install-flynn)

If you prefer you can download the file, read through it and just run it.

This script will take a few minutes to run and output lots of information while it does it.

Setting it up as a cluster

The next thing to do is to let all three nodes know about each other so they can act as a cluster rather than separate instances.

On one of the instances (it doesn't matter which one) run this command:

sudo flynn-host init --init-discovery

This will output a single line like:

https://discovery.flynn.io/clusters/38ad9a5d-e40d-4db7-a8b7-e0f4785e230c

You then use this output in a similar command you run on the other instances:

sudo flynn-host init --discovery \
  https://discovery.flynn.io/clusters/38ad9a5d-e40d-4db7-a8b7-e0f4785e230c

That command will not output anything.

Now we need to ensure that Flynn is running on each of the instances with:

sudo systemctl start flynn-host
sudo systemctl status flynn-host

If the output on all three instances says active (running) then we're good to continue installing Flynn.

DNS Configuration

There are a few records you need to setup. We'll use Civo's DNS service for this. Our domain is flynn.civo.com, so they should have an A record for each host (so you can get to them), a multiple-IP A record (which we achieve with multiple A records) for the flynn.civo.com and a wildcard CNAME for *.flynn.civo.com pointing to flynn.civo.com. Your entries should look like this:

flynn-dns.png

Installing Flynn

One of the instances (it now doesn't matter because they are a cluster), let's install (bootstrap) Flynn:

sudo \
  CLUSTER_DOMAIN=flynn.civo.com \
  flynn-host bootstrap \
  --min-hosts 3 \
  --discovery https://discovery.flynn.io/clusters/38ad9a5d-e40d-4db7-a8b7-e0f4785e230c

When it finishes you'll see a message saying Flynn bootstrapping complete and some important information that we'll need in the next steps.

Accessing Flynn's dashboard

Flynn comes with a built-in web-based dashboard that you can use to manage and scale your apps and attach services. To access it, go to the URL output at the end of bootstrapping - http://dashboard.flynn.civo.com.

First login to the Flynn dashboard

Before you can really use the dashboard, you need to follow the steps onscreen - accepting the TLS CA certificate and logging in using the token given at the end of the bootstrap.

flynn-dashboard-initial.png

After downloading then trusting the CA cert and logging in with the login token given at the end of bootstrapping you should be faced with a screen like this:

flynn-dashboard-no-apps.png

At this point we'll switch over to installing/configuring our command line client and deploying our first application.

Installing the Flynn command line client on your local machine

The Flynn bootstrap process should have output the link for how to install the Flynn CLI but the short version is that on a Mac or Linux machine you can just run:

L=/usr/local/bin/flynn && curl -sSL -A "`uname -sp`" https://dl.flynn.io/cli | zcat >$L && chmod +x $L

After the command is installed you need to connect it to your flynn cluster. The command to do this was also given at the end of your bootstrap command:

flynn cluster add -p SOME_LONG_TOKEN default flynn.civo.com SOME_SHORT_TOKEN

Deploying your first app

Let's first off clone a simple Hello World application. A google search should reveal a few and I've chosen this one at random:

git clone https://github.com/jaustinhughey/hello-world-node-express.git
cd hello-world-node-express

Then we need to create a new application on Flynn for this:

flynn create hello-world
> Created hello-world

If you look at the Flynn Dashboard now you'll see it shown:

flynn-dashboard-first-app.png

We need to make a quick fix (Flynn, or PaaS like Heroku, need to know how to start the service) and then we can push the app to deploy it:

echo "web: node app.js" > Procfile

git add Procfile

git commit -m "Added Procfile for 12-factor app support"
> [master 12e4e53] Added Procfile for 12-factor app support
>  1 file changed, 1 insertion(+)
>  create mode 100644 Procfile

git push flynn
> ...
> =====> Initial web job started
> =====> Application deployed
> To https://git.flynn.civo.com/hello-world.git
>  * [new branch]      master -> master

So finally you should be able to login to your browser and visit https://hello-world.flynn.civo.com (replacing civo.com with your domain name). If you want to add a route (for www.hello-world.com or something) you can either do that from the dashboard or by running a command like this from your checked out project:

flynn route add http hello-world.com
> http/3fbc5b79-49d2-4d57-b09b-1484a9e28337

flynn-dashboard-first-app-launched.png