あらまし
SpinnakerのGetting startを実施した際に
最後のTry it out!の箇所でエラーが出たので回避した設定と
ログを確認した時に気付いて設定を入れた点を以下に記載します。
接続時にInternal_IPアドレスで接続する
問題
そもそもTry it out!手順実行時に失敗した原因がこれ。
bake実行時にspinnakerVMからimageを作成するpackerVMに
SSH接続で接続するのだが、初期設定ではExternal_IPを使用する為
Firewall ruleを独自に設定しているとSSH接続が拒否されてしまう。
(不特定のglobalなIPに対してssh portを解放するの事は
気持ちがいいものではないと僕は思いますので
特定のIP以外からのsshを防ぐ為portを解放していませんでした。)
以下、bake実行時のログとなります。
googlecompute output will be in this color.
==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Creating instance...
googlecompute: Loading zone: us-central1-f
googlecompute: Loading image: ubuntu-1404-trusty-v20150909a in project MY_PROJECT_ID
googlecompute: Loading machine type: n1-standard-1
googlecompute: Loading network: default
googlecompute: Requesting instance creation...
googlecompute: Waiting for creation operation to complete...
googlecompute: Instance has been created!
==> googlecompute: Waiting for the instance to become running...
googlecompute: IP: 104.197.122.31 <- ***External_IPで接続を試みている***
==> googlecompute: Waiting for SSH to become available...
==> googlecompute: Timeout waiting for SSH. <- ***SSHがtimeoutしている***
==> googlecompute: Deleting instance...
googlecompute: Instance has been deleted!
==> googlecompute: Deleting disk...
googlecompute: Disk has been deleted!
Build 'googlecompute' errored: Timeout waiting for SSH.
==> Some builds didn't complete successfully and had errors:
--> googlecompute: Timeout waiting for SSH.
==> Builds finished but no artifacts were created.
解決案
同じnetwork内なのでInternal_IPを使って接続すればいいんじゃないの?
ということで、
/opt/rosco/config/packer/gce.jsonのbuilders.use_internal_ip
に
true
を設定する事でInternal_IP経由でSSHをすることを実現できました。
設定
before
"builders": [{
"type": "googlecompute",
"project_id": "{{user `gce_project_id`}}",
"account_file": "{{user `gce_account_file`}}",
"zone": "{{user `gce_zone`}}",
"source_image": "{{user `gce_source_image`}}",
"image_name": "{{user `gce_target_image`}}",
"image_description": "appversion: {{user `appversion`}}, build_host: {{user `build_host`}}"
}],
after
"builders": [{
"type": "googlecompute",
"project_id": "{{user `gce_project_id`}}",
"account_file": "{{user `gce_account_file`}}",
"zone": "{{user `gce_zone`}}",
"source_image": "{{user `gce_source_image`}}",
"image_name": "{{user `gce_target_image`}}",
"image_description": "appversion: {{user `appversion`}}, build_host: {{user `build_host`}}",
"use_internal_ip": true
}],
確認
設定後にbakeを実行したログがこちら。
Internal_IPを使用して、SSH接続が成功した事がログに記載されています。
==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Creating instance...
googlecompute: Loading zone: asia-east1-c
googlecompute: Loading image: ubuntu-1404-trusty-v20150909a in project MY_PROJECT_ID
googlecompute: Loading machine type: n1-standard-1
googlecompute: Loading network: default
googlecompute: Requesting instance creation...
googlecompute: Waiting for creation operation to complete...
googlecompute: Instance has been created!
==> googlecompute: Waiting for the instance to become running...
googlecompute: IP: 10.240.0.5 <- ***Internal_IPで接続を試みている***
==> googlecompute: Waiting for SSH to become available...
==> googlecompute: Connected to SSH! <- ***SSH接続が成功している***
==> googlecompute: Pausing 30s before the next provisioner...
(snip)
構築されるVMのzoneにasia-east1-cを使用する
こちらはログを見た時に気になって設定を変更した内容になります。
問題
bake実行時にimage作成用に一時的に構築されるpackerVMなんですが
初期設定だとzoneがus-central1-f
に構築されてしまいます。
bake処理実行中にgcloud compute instances list
で確認できます。
$ gcloud compute instances list | grep packer
packer-564fe332-daa6-a0b2-c30b-6c93c188cdfb us-central1-f n1-standard-1 10.240.0.4 104.197.122.31 RUNNING
解決案
spinnakerのVMをasia-east1-c
に構築しているので
/opt/rosco/config/rosco.ymlのgoogle.gce.zone
を
asia-east1-c
に変更することで実現できました。
設定
before
google:
enabled: ${GOOGLE_ENABLED:false}
gce:
bakeryDefaults:
zone: us-central1-f
templateFile: gce.json
operatingSystemVirtualizationSettings:
- os: ubuntu
virtualizationSettings:
sourceImage: ubuntu-1204-precise-v20150910
- os: trusty
virtualizationSettings:
sourceImage: ubuntu-1404-trusty-v20150909a
after
google:
enabled: ${GOOGLE_ENABLED:false}
gce:
bakeryDefaults:
zone: asia-east1-c
templateFile: gce.json
operatingSystemVirtualizationSettings:
- os: ubuntu
virtualizationSettings:
sourceImage: ubuntu-1204-precise-v20150910
- os: trusty
virtualizationSettings:
sourceImage: ubuntu-1404-trusty-v20150909a
roscoの再起動
上記設定後は rosco
の再起動が必要との事で再起動を実施する。
(細かいアーキテクチャは分かっていないので、これから学ぶ予定です。)
$ sudo service rosco restart
確認
設定後にbakeを実行している間にinstance一覧を確認すると
packerVMがasia-east1-c
に構築している事が確認できる。
$ gcloud compute instances list | grep packer
packer-56507378-4c78-9e72-67e8-8af86f122c86 asia-east1-c n1-standard-1 10.240.0.5 104.199.137.139 STAGING
また、先ほどの使いまわしで恐縮だが、ログからも同様に確認ができる。
==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Creating instance...
googlecompute: Loading zone: asia-east1-c <- ***asia-east1-cにVM構築をしている***
googlecompute: Loading image: ubuntu-1404-trusty-v20150909a in project MY_PROJECT_ID
googlecompute: Loading machine type: n1-standard-1
googlecompute: Loading network: default
googlecompute: Requesting instance creation...
googlecompute: Waiting for creation operation to complete...
googlecompute: Instance has been created!
==> googlecompute: Waiting for the instance to become running...
googlecompute: IP: 10.240.0.5
==> googlecompute: Waiting for SSH to become available...
==> googlecompute: Connected to SSH!
==> googlecompute: Pausing 30s before the next provisioner...
(snip)
最後に
Getting startを流しただけなので、Spinnakerでどこまでできるのか
今のシステムに組み込めるのか、など調査や課題はあるのですが
gitへのpushが主なtriggerである既存の第三世代CIにはない運用方法が
あるように思えました。
あと、今回の手順はslackのspinnaker channelで
duftler 氏に教えていただいた内容であり、大変助かりました。