Posted at

CloudFoundry(v194)をbosh-lite上にデプロイする

More than 3 years have passed since last update.


CloudFoundry(v194)をbosh-lite上にデプロイする

事前にインストールするもの

- virtualbox: https://www.virtualbox.org/wiki/Downloads

- vagrant: https://www.vagrantup.com/downloads.html

- vagrant-vbox-snapshot: http://qiita.com/takuan_osho/items/682b776b41989f0b016f

- spiff: https://github.com/cloudfoundry-incubator/spiff/releases

- ruby: https://github.com/sstephenson/rbenv

- cf: https://github.com/cloudfoundry/cli/releases

注意事項

- bosh-liteだけでメモリは8GB必要になる

- bosh-liteはvagrant-haltすると復旧不可になる

-- vagrant-snapshotからは復旧可能

- 稀にvagrant-sshやsnapshotまで使えなくなることがある

-- よくわからなくなったときはvagrant destoryして最初からやり直し


CloudFoundryのインストール

$ mkdir ~/workspace

$ cd ~/workspace
$ git clone https://github.com/cloudfoundry/bosh-lite
$ cd bosh-lite
$ vagrant up
$ bin/add-route

$ gem install bosh_cli --no-rdoc --no-ri

$ bosh target 192.168.50.4 lite

# admin admin でログイン
$ bosh login

#######

$ cd ~/workspace
$ git clone https://github.com/cloudfoundry/cf-release
$ cd cf-release
$ git checkout -b _v194 refs/tags/v194

$ ./update
# (時間がかかる)

$ bosh create release
# (時間がかかる)

$ bosh upload release releases/cf-194.yml

#######

$ cd ~/workspace/bosh-lite
$ wget http://bosh-jenkins-artifacts.s3.amazonaws.com/bosh-stemcell/warden/latest-bosh-stemcell-warden.tgz
$ bosh upload stemcell latest-bosh-stemcell-warden.tgz
$ bin/make_manifest_spiff

$ bosh deploy
# (時間がかかる)

## 状態の確認

$ bosh vms
Deployment `cf-warden'

Director task 4

Task 4 done

+------------------------------------+---------+---------------+--------------+
| Job/index | State | Resource Pool | IPs |
+------------------------------------+---------+---------------+--------------+
| unknown/unknown | running | small_errand | 10.244.0.182 |
| unknown/unknown | running | small_errand | 10.244.0.178 |
| api_z1/0 | running | large_z1 | 10.244.0.138 |
| etcd_z1/0 | running | medium_z1 | 10.244.0.42 |
| ha_proxy_z1/0 | running | router_z1 | 10.244.0.34 |
| hm9000_z1/0 | running | medium_z1 | 10.244.0.142 |
| loggregator_trafficcontroller_z1/0 | running | small_z1 | 10.244.0.150 |
| loggregator_z1/0 | running | medium_z1 | 10.244.0.146 |
| login_z1/0 | running | medium_z1 | 10.244.0.134 |
| nats_z1/0 | running | medium_z1 | 10.244.0.6 |
| postgres_z1/0 | running | medium_z1 | 10.244.0.30 |
| router_z1/0 | running | router_z1 | 10.244.0.22 |
| runner_z1/0 | running | runner_z1 | 10.244.0.26 |
| uaa_z1/0 | running | medium_z1 | 10.244.0.130 |
+------------------------------------+---------+---------------+--------------+

VMs total: 14

# ここで一旦snapshotを作成する
$ vagrant snapshot take cfv194


サンプルアプリをpushして動作確認

$ cf login -a api.10.244.0.34.xip.io --skip-ssl-validation -u admin -p admin

$ cf create-org admin-org
$ cf create-space admin-space -o admin-org
$ cf target -o admin-org -s admin-space

$ cd ~/workspace
$ git clone https://github.com/cloudfoundry/cf-acceptance-tests
$ cd cf-acceptance-tests/assets/golang

$ cf push go1

$ cf apps
Getting apps in org admin-org / space admin-space as admin...
OK

name requested state instances memory disk urls
go1 started 1/1 256M 1G go1.10.244.0.34.xip.io


bindするservicesをdeployする

$ cd ~/workspace

$ wget https://cf-contrib.s3.amazonaws.com/boshrelease-cf-services-contrib-6.tgz
$ bosh upload release boshrelease-cf-services-contrib-6.tgz

$ git clone https://github.com/cloudfoundry-community/cf-services-contrib-release
$ cd cf-services-contrib-release
$ git checkout v6

$ templates/make_manifest warden
$ bosh -n deploy
# (時間がかかる)

## 状態の確認

$ bosh vms
Deployment `cf-services-contrib'

Director task 7

Task 7 done

+----------------------+---------+---------------+-------------+
| Job/index | State | Resource Pool | IPs |
+----------------------+---------+---------------+-------------+
| mongodb_gateway/0 | running | gateway_z1 | 10.244.1.2 |
| mongodb_node/0 | running | node_z1 | 10.244.1.82 |
| postgresql_gateway/0 | running | gateway_z1 | 10.244.1.10 |
| postgresql_node/0 | running | node_z1 | 10.244.1.90 |
| rabbit_gateway/0 | running | gateway_z1 | 10.244.1.6 |
| rabbit_node/0 | running | node_z1 | 10.244.1.86 |
| redis_gateway/0 | running | gateway_z1 | 10.244.1.14 |
| redis_node/0 | running | node_z1 | 10.244.1.94 |
+----------------------+---------+---------------+-------------+

VMs total: 8
Deployment `cf-warden'

Director task 8

Task 8 done

+------------------------------------+---------+---------------+--------------+
| Job/index | State | Resource Pool | IPs |
+------------------------------------+---------+---------------+--------------+
| unknown/unknown | running | small_errand | 10.244.0.178 |
| unknown/unknown | running | small_errand | 10.244.0.182 |
| api_z1/0 | running | large_z1 | 10.244.0.138 |
| etcd_z1/0 | running | medium_z1 | 10.244.0.42 |
| ha_proxy_z1/0 | running | router_z1 | 10.244.0.34 |
| hm9000_z1/0 | running | medium_z1 | 10.244.0.142 |
| loggregator_trafficcontroller_z1/0 | running | small_z1 | 10.244.0.150 |
| loggregator_z1/0 | running | medium_z1 | 10.244.0.146 |
| login_z1/0 | running | medium_z1 | 10.244.0.134 |
| nats_z1/0 | running | medium_z1 | 10.244.0.6 |
| postgres_z1/0 | running | medium_z1 | 10.244.0.30 |
| router_z1/0 | running | router_z1 | 10.244.0.22 |
| runner_z1/0 | running | runner_z1 | 10.244.0.26 |
| uaa_z1/0 | running | medium_z1 | 10.244.0.130 |
+------------------------------------+---------+---------------+--------------+

VMs total: 14


servicesが使えるように設定する


# create-serviceするための設定
$ cf create-service-auth-token mongodb core c1oudc0w
$ cf create-service-auth-token postgresql core c1oudc0w
$ cf create-service-auth-token rabbitmq core c1oudc0w
$ cf create-service-auth-token redis core c1oudc0w

# アプリとserviceの通信許可設定
$ cf curl /v2/security_groups -X POST -d '
{
"name": "fullaccess",
"rules": [
{
"protocol": "all",
"destination": "0.0.0.0/0"
}
]
}'

$ cf bind-security-group fullaccess admin-org admin-space

# ここで一旦snapshotを作成する
$ vagrant snapshot take addservices


サンプルアプリ(redis)をpushして動作確認

$ cd ~/workspace

$ git clone https://github.com/k-kurumi/cf_sample_app1
$ cd cf_sample_app1

# manifest.ymlにあるmyredis1を作る
$ cf create-service redis default myredis1

$ cf push

# bind自体はmanifest.ymlを元に実施される
# serviceはアプリの環境変数VCAP_SERVICESから参照する

# redisでインクリメントされることを確認
$ curl myapp1.10.244.0.34.xip.io
Hello World! I have been seen 1 times.

$ curl myapp1.10.244.0.34.xip.io
Hello World! I have been seen 2 times.