Setting up Flynn PaaS on EC2 Instances

Continuing from The Game of Deployment, Today we will discuss from how to start from setup Flynn clusters to how to deploy your app to these clusters. This serves as an end to end guide for Flynn, from my experience researching Flynn as a possible deployment management candidate.

Basically, you would need to follow certain steps and everything would be ready. It's just that simple.

For a nice smooth performance of the cluster, Flynn recommends, each node should be a machine with 2 GB Ram, 40 GB Storage, 2 CPUs with 2 cores each.
And for high availability, a cluster should have at least 3 nodes.

Although Flynn runs on both Ubuntu 14.04 & 16.04 while setting up I faced lesser issues on Ubuntu 16.04.
We would assume you would setup Flynn on yourflynn.yourdomainname.com

Setup Flynn Cluster

Run:

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

This would install Flynn. Repeat this in each machine which should act as a node in the cluster.

Make sure the nodes have all their TCP & UDP ports open between them internally.
That is if there are two nodes -> node1 & node2, they should be able to communicate among themselves through any of the ports.
Although all the ports do not need to be open to the external world.

Open the following ports to be accessed by the external world.

80 -> HTTP ports

443 -> https ports

3000-3500 -> TCP Ports which are used by certain processes like Postgres,MySQL etc.

Note: If you cannot define the internally & externally open ports separately, you should put a firewall blocking external access to the ports.

Next on, you would need to generate a token which would allow the cluster to discover each node during bootstrapping of the cluster.

Setup DNS Names -> Since It is a clustered approach you would need to setup DNS Records that point to each of the nodes.
You would need to set A records for each of the node & a wildcard domain cname to the cluster domain name.

Make sure you have the file which lists all the dependencies. For ex:- requirements.txt in Python, package.json in NodeJs.

The above steps should be sufficient to deploy. But you can do further customization.

Generally, the latest version of the detected environment is used. But if you want your application to run on a particular environment, you can create a file "runtime.txt" which would list the environment. runtime.txt containing one line -> python-2.7.8

Flynn similar to Heroku uses Buildpacks to compile your application. Right from detecting your app environment to installing and running your dependencies.
Sometimes it might be possible that you may want to use multiple buildpacks.
Ex:-
You may want to install extra Linux dependencies before you compile.

Or you may want to

Run an application which is not yet supported by the default buildpack like a Tornado or CherryPy Application.

For this, you would need to create a file ".buildpacks", and list out URL of every buildpack that you need.

After the push is completed you will see that the application is building. If any errors occur, you will get them in the command line.

Additional Information

Setting up local Flynn

You can try Flynn on your local machine before you actually set up on the cloud, just to get a bit of taste of it.
You would need VirtualBox & Vagrant Box installed.
Copy the Flynn Repo
git clone https://github.com/flynn/flynn

Setup :-

make init
make dashboard

Start & Shutdown

make down
make up

Logging in Flynn

Since Flynn is a cloud based clustered solution, meaning you will probably not be able to retrieve your logs, and you could lose them with each deployment.
There are two solutions to this

You can send all the INFO,DEBUG,WARNING,ERROR messages to stdout/stderr and it will be automatically be logged by flynn.

If you would like to segregate logging of different modules, you can use a remote syslog server and send your logs there.

Shauryadeep Chaudhuri

Engineer

Joined July 2017. Major in Computer Science Engineering from West Bengal University of Technology. Has worked across different development stacks in the past. Loves the aesthetics of Python as a programming language. An avid traveler, tries to travel as much as possible.