Flynn とは
Docker(実装はGo)を使ったOSSなPaaS。
準備
公式のそのまんまやってみる。
flynn/demo at master · flynn/flynn : https://github.com/flynn/flynn/tree/master/demo
$ git clone https://github.com/flynn/flynn
$ cd flynn/demo
$ vagrant up
OSX だと xz を brew でインストールする必要がある。
$ brew install xz
インストール
Go 特有のアレでインストール。
$ L=/usr/local/bin/flynn && curl -sL -A "`uname -sp`" https://cli.flynn.io/flynn.gz | zcat >$L && chmod +x $L
これでflynn のコマンドが使える。
使い方
flynn -h
usage: flynn [-a <app>] <command> [<args>...]
Options:
-a <app>
-h, --help
Commands:
help show usage for a specific command
cluster manage clusters
create create an app
apps list apps
ps list jobs
kill kill a job
log get job log
scale change formation
run run a job
env manage env variables
route manage routes
provider manage resource providers
resource provision a new resource
key manage SSH public keys
release add a docker image release
version show flynn version
See 'flynn help <command>' for more information on a specific command.
デプロイの準備
クラスタを登録する
今回は、$ vagrant up
実行時の最後のログに出力されているものをコピペ。(デモ用に用意してくれてるっぽい)
...
==> default:
==> default: flynn cluster add -g demo.localflynn.com:2222 -p XXXXXXXXXXXXXXXX default https://demo.localflynn.com xxxxxxxxxxxxxxxxxxxxxxxx
コピペ。
$ flynn cluster add -g demo.localflynn.com:2222 -p XXXXXXXXXXXXXXXX default https://demo.localflynn.com xxxxxxxxxxxxxxxxxxxxxxxx
オプションの説明。
$ flynn cluster add
usage: flynn cluster
flynn cluster add [-g <githost>] [-p <tlspin>] <cluster-name> <url> <key>
flynn cluster remove <cluster-name>
名前解決
Vagrantfile で設定されているアドレスとクラスタに設定したドメインを対応づける。
192.168.84.42 demo.localflynn.com example.demo.localflynn.com
鍵登録
$ flynn key add ~/.ssh/id_rsa.pub
デプロイ
サンプルアプリを動かしてみる。
$ git clone https://github.com/flynn/nodejs-flynn-example
$ cd nodejs-flynn-example
$ flynn create example
remote に flynnが追加されている。
$ git remote -v
flynn ssh://git@demo.localflynn.com:2222/example.git (fetch)
flynn ssh://git@demo.localflynn.com:2222/example.git (push)
origin https://github.com/flynn/nodejs-flynn-example (fetch)
origin https://github.com/flynn/nodejs-flynn-example (push)
プッシュ!
$ git push flynn master
操作は Heroku ライクでわかりやすい。
スケール
web の プロセスを3つにしてみる。
$ flynn scale web=3
確認
$ flynn ps
ID TYPE
flynn-69af57a8234a45d3b1d2dcad7f697838 web
flynn-916c8a827a5745728d1641c01a17d472 web
flynn-d96234695fc6400d9e025252525919c1 web
http://example.demo.localflynn.com/ にブラウザからみれる。
3つの webプロセスにバランシングされている。
$ curl http://example.demo.localflynn.com
Hello from Flynn on port 55007 from container 916c8a827a5745728d1641c01a17d472
$ curl http://example.demo.localflynn.com
Hello from Flynn on port 55006 from container d96234695fc6400d9e025252525919c1
これで自分用のPaaSができる。すごい。
デモのチュートリアルやっただけなので、内部構造はもうちょっと調べてみようと思うます。
参考・引用
- DockerによるマルチホストのPaaS flynnの概要とそのアーキテクチャー | SOTA : http://deeeet.com/writing/2014/07/07/flynn/
- flynn/demo at master · flynn/flynn : https://github.com/flynn/flynn/tree/master/demo
ちな
複数のマシン間で共有できるようにする仕組みでは、etcdというKVSが使われていて、Raftというアルゴリズムおよびそのプロトコルの考えをベースにしている。Docker、Flynn、CoreOSを調べていくと必ずでてくる。
Raftのアルゴリズムについては下記のサイトがとてもわかりやすい。
Raft : http://thesecretlivesofdata.com/raft/
- Etcd - r7km/s : http://r7kamura.github.io/2014/02/26/etcd.html
- etcd総選挙を眺めてみる - Qiita : http://qiita.com/ksato9700/items/9b44a95ce27ac23a94e1