Googel Compute Engine で公式OSイメージに CoreOS が追加されました。
Google Cloud Platform Blog: Official CoreOS images are now available on Google Compute Engine
http://googlecloudplatform.blogspot.jp/2014/05/official-coreos-images-are-now-available-on-google-compute-engine.html
いままでもCoreOSインスタンスは独自OSをアップロードするやり方でできたのですがこれからはその手間が不要になりますね。
(∩´∀`)∩ワーイ
ただ、2014年5月26日現在はまだリストにCoreOSが出てきていません。
$ gcutil listimages
+-------------------------------------------------------------------------+-------------+--------+
| name | deprecation | status |
+-------------------------------------------------------------------------+-------------+--------+
| projects/centos-cloud/global/images/centos-6-v20140415 | | READY |
+-------------------------------------------------------------------------+-------------+--------+
| projects/debian-cloud/global/images/backports-debian-7-wheezy-v20140415 | | READY |
+-------------------------------------------------------------------------+-------------+--------+
| projects/debian-cloud/global/images/debian-6-squeeze-v20130926 | DEPRECATED | READY |
+-------------------------------------------------------------------------+-------------+--------+
| projects/debian-cloud/global/images/debian-7-wheezy-v20140415 | | READY |
+-------------------------------------------------------------------------+-------------+--------+
| projects/rhel-cloud/global/images/rhel-6-v20140415 | | READY |
+-------------------------------------------------------------------------+-------------+--------+
| projects/suse-cloud/global/images/sles-11-sp3-v20140306 | | READY |
+-------------------------------------------------------------------------+-------------+--------+
すぐに CoreOS インスタンスを作ってみたい場合は、公式ブログにあるように直接指定してしまいましょう!
下記は公式ブログの内容の抜粋です。
※初めて Google Cloud SDK を利用する場合は、以下を実行する前に下記を参考に設定してみてください(ステマ)。
googlecomputeengine - Google Compute Engine 入門 - Qiita
http://qiita.com/yuko/items/460ac35d8706e8df1290
1.etcdの設定
1-1. etcdのクラスタ用トークンを取得
$ curl https://discovery.etcd.io/new
https://discovery.etcd.io/b97f446100a293c8107500e11c34864b
1-2. インスタンス作成用の設定ファイルを作成
yamlファイルで作成します。
上記で取得したトークンを記載して、同じクラスタになるようにします。
下記は同じzoneにインスタンスを作成する場合の例です。$private_ipv4
を利用しています。
もし、異なるRegionやZoneに同じクラスタを作成したい場合は$public_ipv4
を使ってねとのことです。
$ cat cloud-config.yaml
# cloud-config
coreos:
etcd:
# generate a new token for each unique cluster from https://discovery.etcd.io/new
discovery: https://discovery.etcd.io/b97f446100a293c8107500e11c34864b
# multi-region and multi-cloud deployments need to use $public_ipv4
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
2.CoreOSインスタンスの作成
上記で指定したyamlファイルを利用して同時に3つのCoreOSインスタンスを起動してみましょう。
CoreOSのイメージはまだStableなものはなくて、BetaとAlphaです。
Beta : projects/coreos-cloud/global/images/coreos-beta-310-1-0-v20140508
Alpha : projects/coreos-cloud/global/images/coreos-alpha-324-1-0-v20140522
今回はブログと同じBetaでやってみます。
また、公式ブログでの Region は us-central なんですが、せっかくなので asia-east でやってみます。 :)
下記コマンドの<project-id>
のところは、自分のプロジェクトIDに置き換えて実行して下さい。
$ gcutil --project=<project-id> addinstance
--image=projects/coreos-cloud/global/images/coreos-beta-310-1-0-v20140508
--persistent_boot_disk --zone=asia-east1-a --machine_type=n1-standard-1
--metadata_from_file=user-data:cloud-config.yaml core1 core2 core3
INFO: Waiting for insert of instance core2. Sleeping for 3s.
INFO: Waiting for insert of instance core1. Sleeping for 3s.
INFO: Waiting for insert of instance core3. Sleeping for 3s.
INFO: Waiting for insert of instance core2. Sleeping for 3s.
INFO: Waiting for insert of instance core1. Sleeping for 3s.
INFO: Waiting for insert of instance core3. Sleeping for 3s.
INFO: Waiting for insert of instance core2. Sleeping for 3s.
INFO: Waiting for insert of instance core3. Sleeping for 3s.
INFO: Waiting for insert of instance core1. Sleeping for 3s.
INFO: Waiting for insert of instance core2. Sleeping for 3s.
INFO: Waiting for insert of instance core3. Sleeping for 3s.
INFO: Waiting for insert of instance core1. Sleeping for 3s.
Table of resources:
+-------+----------------+-----------------+--------------+---------+
| name | network-ip | external-ip | zone | status |
+-------+----------------+-----------------+--------------+---------+
| core1 | 10.240.184.120 | 107.167.18x.xx | asia-east1-a | RUNNING |
+-------+----------------+-----------------+--------------+---------+
| core2 | 10.240.22.204 | 107.167.18x.xxx | asia-east1-a | RUNNING |
+-------+----------------+-----------------+--------------+---------+
| core3 | 10.240.121.83 | 107.167.18x.xx | asia-east1-a | RUNNING |
+-------+----------------+-----------------+--------------+---------+
Table of operations:
+---------------------------------------------------------+--------+-------------------------------+----------------+
| name | status | insert-time | operation-type |
+---------------------------------------------------------+--------+-------------------------------+----------------+
| operation-1401022720679-4fa3905969c58-58a14058-9501d036 | DONE | 2014-05-25T05:58:41.078-07:00 | insert |
+---------------------------------------------------------+--------+-------------------------------+----------------+
| operation-1401022720703-4fa390596fa18-2a786afc-baadb81e | DONE | 2014-05-25T05:58:41.031-07:00 | insert |
+---------------------------------------------------------+--------+-------------------------------+----------------+
| operation-1401022720680-4fa390596a040-ca073aed-6052de8d | DONE | 2014-05-25T05:58:41.155-07:00 | insert |
+---------------------------------------------------------+--------+-------------------------------+----------------+
できた!
では作成した core1 に gcutil コマンドでログインしてみましょう。
<project-id>
のところは、自分のプロジェクトIDに置き換えて試してみてください。
~ $ gcutil --project=<project-id> ssh --ssh_user=core core1
CoreOS (beta)
core@core1 ~ $
ログインできた!
3.Dockerでコンテナを追加
一行echoするだけのシンプルなサービスを作成してみましょう。
$ vi example.service
$ cat example.service
[Unit]
Description=MyApp
After=docker.service
Requires=docker.service
[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/docker run busybox /bin/echo 'I was scheduled with fleet!'
起動してみましょう。
$ fleetctl start example.service
Job example.service scheduled to acd37c81.../10.240.132.216
$ fleetctl list-units
UNIT LOAD ACTIVE SUB DESC MACHINE
example.service loaded active running MyApp acd37c81.../10.240.132.216
起動できた!
さてメッセージは出てるかな?
$ fleetctl status example.service
● example.service - MyApp
Loaded: loaded (/run/systemd/system/example.service; static)
Active: active (exited) since Mon 2014-05-26 01:17:15 UTC; 12min ago
Process: 10036 ExecStart=/usr/bin/docker run busybox /bin/echo I was scheduled with fleet! (code=exited, status=0/SUCCESS)
Main PID: 10036 (code=exited, status=0/SUCCESS)
May 26 01:17:15 core1.c.hoge.internal systemd[1]: Started MyApp.
May 26 01:17:19 core1.c.hoge.internal docker[10036]: Unable to find image 'busybox' locally
May 26 01:17:19 core1.c.hoge.internal docker[10036]: Pulling repository busybox
May 26 01:17:45 core1.c.hoge.internal docker[10036]: I was scheduled with fleet!
I was scheduled with fleet!
って出てますので成功です!
下記リンクを参考にして色々試してみてくださいね。
enjoy!
参考リンク
Containers on Google Cloud Platform - Google Compute Engine — Google Developers
https://developers.google.com/compute/docs/containers
Official CoreOS Images on Google Compute Engine
http://coreos.com/blog/official-gce-images/
Google Compute Engine : CoreOS Document
http://coreos.com/docs/running-coreos/cloud-providers/google-compute-engine/
Google Compute EngineがOSの選択肢にCoreOSを加える–併せて仮想化の主役はDockerへ | TechCrunch Japan
http://jp.techcrunch.com/2014/05/24/20140523google-makes-coreos-a-first-class-citizen-on-its-cloud-platform/
Dockerに最適化したOSイメージをGoogle Compute Engineが提供開始。CoreOSも利用可能に - Publickey
http://www.publickey1.jp/blog/14/dockerosgoogle_compute_enginecoreos.html