書いたままになっていた記事を今更公開。
CoreOS のうんちく
CoreOS の基板
こちら(CoreOS に入門した)のブログ記事がとても参考になったので写経しておく。
- Docker
- etcd
- fleet
Docker
- CoreOS ではサービスやアプリケーションは全て Docker コンテナ内で動かす
- コンテナ内で動かすことでプロセスの隔離、安全なリソース共有、アプリケーションのポータビリティを確保している
etcd
fleet
- CoreOS の各ノードで稼働させるアプリケーション、サービスコンテナのスケジューリングとコンテナの管理を行う
環境
CoreOS の準備
git clone
$ git clone https://github.com/coreos/coreos-vagrant.git $ cd coreos-vagrant
user-data の修正
- 修正の前に token の取得
$ curl -s https://discovery.etcd.io/new https://discovery.etcd.io/95b2bdea861a17113d7462b22aac0b5d
- user-data の修正
$ diff -u user-data.sample user-data --- user-data.sample Sat Mar 14 21:49:50 2015 +++ user-data Sat May 23 16:19:10 2015 @@ -5,6 +5,7 @@ # generate a new token for each unique cluster from https://discovery.etcd.io/new # WARNING: replace each time you 'vagrant destroy' #discovery: https://discovery.etcd.io/<token> + discovery: https://discovery.etcd.io/c91d6878e0c4d6dac4f6be9799178299 addr: $public_ipv4:4001 peer-addr: $public_ipv4:7001 fleet:
基本的には discovery の修正のみ。
Vagrantfile の修正
- 起動する CoreOS ノードの台数を指定
$num_instances = 2
とりあえず 2 台起動。
クラスタ構築
vagrant up
vagrant up
以下のようにダラダラと起動メッセージを眺める。
$ vagrant up Bringing machine 'core-01' up with 'virtualbox' provider... Bringing machine 'core-02' up with 'virtualbox' provider... ==> core-01: Importing base box 'coreos-alpha'... ==> core-01: Matching MAC address for NAT networking... ==> core-01: Checking if box 'coreos-alpha' is up to date... ==> core-01: A newer version of the box 'coreos-alpha' is available! You currently ==> core-01: have version '618.0.0'. The latest is version '681.0.0'. Run ==> core-01: `vagrant box update` to update. ==> core-01: Setting the name of the VM: coreos-vagrant_core-01_1432365605662_58138 ==> core-01: Clearing any previously set network interfaces... ==> core-01: Preparing network interfaces based on configuration... core-01: Adapter 1: nat core-01: Adapter 2: hostonly ==> core-01: Forwarding ports... core-01: 22 => 2222 (adapter 1) ==> core-01: Running 'pre-boot' VM customizations... ==> core-01: Booting VM... ==> core-01: Waiting for machine to boot. This may take a few minutes... core-01: SSH address: 127.0.0.1:2222 core-01: SSH username: core core-01: SSH auth method: private key core-01: Warning: Connection timeout. Retrying... ==> core-01: Machine booted and ready! ==> core-01: Setting hostname... ==> core-01: Configuring and enabling network interfaces... ==> core-01: Running provisioner: file... ==> core-01: Running provisioner: shell... core-01: Running: inline script ==> core-02: Importing base box 'coreos-alpha'... ==> core-02: Matching MAC address for NAT networking... ==> core-02: Checking if box 'coreos-alpha' is up to date... ==> core-02: A newer version of the box 'coreos-alpha' is available! You currently ==> core-02: have version '618.0.0'. The latest is version '681.0.0'. Run ==> core-02: `vagrant box update` to update. ==> core-02: Setting the name of the VM: coreos-vagrant_core-02_1432365638253_97823 ==> core-02: Fixed port collision for 22 => 2222. Now on port 2200. ==> core-02: Clearing any previously set network interfaces... ==> core-02: Preparing network interfaces based on configuration... core-02: Adapter 1: nat core-02: Adapter 2: hostonly ==> core-02: Forwarding ports... core-02: 22 => 2200 (adapter 1) ==> core-02: Running 'pre-boot' VM customizations... ==> core-02: Booting VM... ==> core-02: Waiting for machine to boot. This may take a few minutes... core-02: SSH address: 127.0.0.1:2200 core-02: SSH username: core core-02: SSH auth method: private key core-02: Warning: Connection timeout. Retrying... ==> core-02: Machine booted and ready! ==> core-02: Setting hostname... ==> core-02: Configuring and enabling network interfaces... ==> core-02: Running provisioner: file... ==> core-02: Running provisioner: shell... core-02: Running: inline script
vagrant ssh でノードにログイン
vagrant ssh core-01 vagrant ssh core-02
クラスタ構成の確認
fleetctl でクラスタノードの一覧を取得する。
core@core-01 ~ $ fleetctl list-machines -l MACHINE IP METADATA 895ab8ccdaea4e13ad7ae277332d1c9b 172.17.8.102 - bb0ae91f41c6418da69e0587aa7e6558 172.17.8.101 - core@core-02 ~ $ fleetctl list-machines -l MACHINE IP METADATA 895ab8ccdaea4e13ad7ae277332d1c9b 172.17.8.102 - bb0ae91f41c6418da69e0587aa7e6558 172.17.8.101 -
簡単ばい
discovery.etcd.io を使えば discovery 用の etcd を構築しないで良いので楽やろうもん。