Download - BOSHでお手軽CFデプロイon AWS
BOSH でお手軽 CF デプロイon AWS
Iwasaki Yudai @i_yudai
NTT Laboratory
Software Innovation Center
2013-08-23
AWS環境でのCFインスタンス構築
– MicroBOSH
– Cloud Foundry
–ビルトインサービス
今日の内容
2
BOSHとCloud Foudryのインストール
3
Based on:
Dr Nic’s “Build Your Own Heroku With Open Source Cloud Foundry” https://github.com/cloudfoundry-community/bosh-cloudfoundry/blob/master/tutorials/
AWSアカウント
AWS使用料
Ruby1.9.3
Git
必要なもの
4
$500/月 程度 (ap-northeast-1 Tokyo)
–生成されるVM
• m1.small * 4 (Cloud Foundry)
• m1.small * 1 (Inception Server)
• m1.medium * 1 (MicroBOSH)
–その他
• Elastic IP * 2
• Volumes が数十GB
AWS使用料について
Inceptionサーバとは
–諸般の事情によりus-east-1以外のリージョンで必要となる踏み台サーバ
– inception-serverを使用 • https://github.com/cloudfoundry-community/inception-server
Inception Serverのセットアップ(1)
# Gem のインストール
$ gem install inception-server
Inception Serverのセットアップ(2)
# 新しいInceptionサーバーを起動
$ inception-server deploy 1. AWS 2. OpenStack Choose your infrastructure: 1 Using provider AWS Access key: *********************** Secret key: ******************************** 1. *US East (Northern Virginia) Region (us-east-1) 2. US West (Oregon) Region (us-west-2) 3. US West (Northern California) Region (us-west-1) 4. EU (Ireland) Region (eu-west-1) 5. Asia Pacific (Singapore) Region (ap-southeast-1) 6. Asia Pacific (Sydney) Region (ap-southeast-2) 7. Asia Pacific (Tokyo) Region (ap-northeast-1) 8. South America (Sao Paulo) Region (sa-east-1) Choose AWS region: 7 Confirming: Using AWS/ap-northeast-1 ....
注)使用しない Elastic IPが 払い出されているので削除する
Inception Serverのセットアップ(3)
# InceptionサーバーにSSHで接続
$ inception-server ssh # SSH鍵を生成しておく
$ ssh-keygen -N '' -f ~/.ssh/id_rsa # 少しだけ細かい環境の修正(Gemをインストールできるようにする)
$ sudo usermod -a -G rvm ubuntu $ sudo chmod g+w /usr/local/rvm –R # グループ変更を反映するために再接続する
$ exit $ inception-server ssh
以降の操作はすべてInceptionサーバ上で行います
bosh-bootstrap を使用する – https://github.com/cloudfoundry-community/bosh-cloudfoundry
– MicroBOSH を1コマンドでデプロイできる
– Inceptionサーバ上で使用する場合はアクセスキーの再入力は不要
MicroBOSHのセットアップ(1)
# Gem のインストール
$ gem install bosh-bootstrap
MicroBOSHのセットアップ(2)
$ bosh-bootstrap deploy Auto-detected infrastructure API credentials at ~/.fog (override with $FOG) 1. AWS (default) 2. Alternate credentials Choose an auto-detected infrastructure: 1 Using provider AWS 1. *US East (Northern Virginia) Region (us-east-1) 2. US West (Oregon) Region (us-west-2) 3. US West (Northern California) Region (us-west-1) 4. EU (Ireland) Region (eu-west-1) 5. Asia Pacific (Singapore) Region (ap-southeast-1) 6. Asia Pacific (Sydney) Region (ap-southeast-2) 7. Asia Pacific (Tokyo) Region (ap-northeast-1) 8. South America (Sao Paulo) Region (sa-east-1) Choose AWS region: 7 Confirming: Using AWS/ap-northeast-1 ...
MicroBOSHのセットアップ(3)
# bosh-bootstrap deploy の実行結果の続き # 最後から3行目に表示される IP アドレスが MicroBOSH のIPアドレスとなる
... WARNING! Your target has been changed to `https://203.0.113.1:25555'! Deployment set to '/home/ubuntu/.microbosh/deployments/firstbosh/micro_bosh.yml‘ Deployed `firstbosh/micro_bosh.yml' to `https://firstbosh:25555', took 00:19:34 to complete # MicroBOSH をターゲットする
$ bosh target https://203.0.113.1:25555 Target set to `firstbosh‘ Your username: admin Enter password: admin Logged in as `admin'
bosh-cloudfoundry を使用する – https://github.com/cloudfoundry-community/bosh-cloudfoundry
– BOSH CLIのプラグイン – Deployment Manifestを自動生成してくれる
事前準備
– Elastic IPを1つ払いだしておく • 例:203.0.113.2
– Security Groupを作っておく • 名前: cf • 開放ポート:
–TCP (Source 0.0.0.0/0): 22, 80, 443 –TCP (Source 同一SG): 1-65535 –UDP(Source 同一SG): 1-65535
Cloud Foundryのセットアップ(1)
Cloud Foundryのセットアップ(2)
# 最新の BOSH CLI をインストールする
$ gem install bosh_cli -v "~> 1.5.0.pre" ¥ --source https://s3.amazonaws.com/bosh-jenkins-gems/ # bosh-cloudfoundryのインストール
$ gem install bosh-cloudfoundry # デプロイの準備(cr-releaseのダウンロードなど)
$ bosh prepare cf
Cloud Foundryのセットアップ(3)
$ bosh create cf --ip 203.0.113.2 --security-group cf Fetching bosh information OK CPI: aws DNS mapping: 203.0.113.2.xip.io --> ["203.0.113.2"] Deployment name: cf-1377155859 Deployment size: medium Persistent disk: 4096 Security group: cf Validating deployment size OK Resolve DNS OK Resolve DNS 'api.203.0.113.2.xip.io' to IP '203.0.113.2' OK `api.203.0.113.2.xip.io' maps to 203.0.113.2 Resolve DNS OK Resolve DNS 'demoapp.203.0.113.2.xip.io' to IP '203.0.113.2' OK `demoapp.203.0.113.2.xip.io' maps to 203.0.113.2 Security group cf exists with ports 22, 80, 443, 4222 (type 'yes' to continue): yes Creating Cloud Foundry (type 'yes' to continue): yes Checking/creating /home/ubuntu/deployments/cf for deployment files OK Creating deployment file /home/ubuntu/deployments/cf/cf-1377155859.yml OK Deployment set to `/home/ubuntu/deployments/cf/cf-1377155859.yml' Getting deployment properties from director... Unable to get properties list from director, trying without it... Compiling deployment manifest... Cannot get current deployment information from director, possibly a new deployment Please review all changes carefully Deploying `cf-1377155859.yml' to `firstbosh' (type 'yes' to continue): yes ...
Cloud Foundryのセットアップ(4)
# デプロイされた VM の確認
$ bosh vms ... +-----------+---------+---------------+-----------------------------+ | Job/index | State | Resource Pool | IPs | +-----------+---------+---------------+-----------------------------+ | api/0 | running | small | 10.122.54.35, 203.0.113.2 | | core/0 | running | small | 10.121.11.212 | | data/0 | running | small | 10.121.14.213 | | dea/0 | running | small | 10.122.29.169 | +-----------+---------+---------------+-----------------------------+ VMs total: 4 # CFの設定値を確認 # common_password が admin ユーザのパスワードになる
$ bosh show cf attributes Fetching bosh information OK Immutable attributes: common_password: e80011989a71 deployment_size: medium name: cf-1377155859 Mutable (changable) attributes: ip_addresses: ["203.0.113.2"] persistent_disk: 4096 security_group: cf dns: 203.0.113.2.xip.io
Cloud Foundryのセットアップ(5)
# cf コマンドのインストール # 今回インストールされるCFは 5.x に対応していないので 4.2.8
$ gem install cf –v 4.2.8 # デフォルトのターゲットは xip.io で設定されている # 例)api.203.0.113.2.xip.io
$ cf target api.203.0.113.2.xip.io # admin ユーザでログイン # パスワードは前頁参照
$ cf login admin target: http://api.203.0.113.2.xip.io Password> e80011989a71 Authenticating... OK There are no spaces. You may want to create one with create-space.... OK
bosh create cf のオプション
– --size • VMの台数(medium, large, xlarge)
•デフォルトはmedium
– --domain •ドメイン名
•デフォルトは <IP Address>.xip.io
個別の設定
– deploymentsディレクトリ内のマニフェストファイルを手動で編集して bosh
deploy
Cloud Foundryのカスタマイズ
ビルトインサービスの追加
ビルトインサービスは別途インストールす
る必要がある – https://github.com/cloudfoundry/cf-services-contrib-release
–コミュニティ版
• cf-services-releaseはPivotalがメンテナンスしているがMySQLしかない
m1.small * 8 が追加で必要
ビルトインサービスを追加する
19
ビルトインサービスのデプロイ
# ソースコードを Clone
$ git clone https://github.com/cloudfoundry/cf-services-contrib-release.git # 最新版で構成するために、dev リリースを生成する
$ cd cf-services-contrib-release $ git submodule update --init –recursive $ bosh create release # BOSH にリリースをアップロード
$ bosh upload release dev_releases/cf-services-contrib-1.1-dev.yml # デプロイメントマニフェストを記述 # 変更点は gist 参照のこと:https://gist.github.com/yudai/6308528
$ vi examples/dns-all.yml # デプロイの実行
$ bosh deployment example/dns-all.yml $ bosh deploy
ビルトインサービスの使用
# AUTH TOKEN の登録 # Tokenの値はデプロイメントマニフェストに記述されている # postgres 以外のサービスについても同様に実行する
$ cf create-service-auth-token Label> postgresql Token> POSTGRESQL_SERVICE_TOKEN Creating service auth token... OK # 使用可能なサービスの一覧を表示して確認
$ cf services --marketplace Getting services... OK service version provider plans description blob 0.51 core default Blob store elasticsearch 0.20 core free Elasticsearch search service memcached 1.4 core default Memcached in-memory cache mongodb 2.2 core default MongoDB NoSQL database postgresql 9.2 core default PostgreSQL database rabbitmq 3.0 core default RabbitMQ message queue redis 2.6 core default Redis key-value store