Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Rancher最速セットアップ理論 プロジェクトr to the next stage

262 views

Published on

Rancher Fastest Setup Theory, Project R to the Next Stage

Published in: Software
  • Be the first to comment

Rancher最速セットアップ理論 プロジェクトr to the next stage

  1. 1. Rancher最速 セットアップ理論 プロジェクトR to the Next Stage       Masayoshi Nomura / @nmrmsys    2018/01/25 Rancher Meetup #03 in Osaka 1 / 16
  2. 2.  ■ なまえ: 野村 昌由  ■ 業務システム開発   とインフラ業  ■ 開発に復帰したはずがインフラ   シェル芸は実⽤主義派、Docker   Rancher、最近はPostgreSQL、   時系列DB、データ分析、IoTも  ■ 所属してる会社が絶賛⼈⼿不⾜   iOS・業務・インフラ・ハード・   その他スゴ腕エンジニアの⽅々   お助け下さい!🐟  @nmrmsys ⾃⼰紹介 2 / 16
  3. 3. 会社紹介   事業所は、新⼤阪、新橋、⼤連、ロス辺りにあります。 3 / 16
  4. 4. 今⽇話す内容 AWSでCloudFormationを使って Rancher環境をサクッと作る⽅法 RancherOSの Community AMIへ cloud-initで Serverをセットアップ 起動スクリプトで Customホスト追加 エージェント実⾏する所まで⾃動化 4 / 16
  5. 5. まずはここから Rancherを最速でセットアップする奴 5 / 16
  6. 6. なぜ最⼩構成か Rancherは主に検証環境で利⽤する為 作業後は簡単スタック停⽌/削除したい 最⼩構成であれば必要な時だけの スケールアップ・ダウンもかなり⾃由 ネットワーク設定等も複雑にならず 考える事が少なくなって取り回しが楽 6 / 16
  7. 7. CloudFormationでインスタンス作成 AWSTemplateFormatVersion: 2010-09-09 Description: Rancher Server Explosion Speed Stack # Create Stack Resources: RancherServer: Type: AWS::EC2::Instance Properties: ImageId: !FindInMap [RancherAMI, !Ref 'AWS::Region', OsOnly] InstanceType: !Ref ServerInstanceType SubnetId: !Ref SubnetId SecurityGroupIds: [!Ref RancherServerSG] KeyName: !Ref KeyName Tags: - Key: Name Value: rancher-server Monitoring: True UserData: Fn::Base64: !Sub | #cloud-config こちらもなるべく最⼩限の設定で 7 / 16
  8. 8. RancherOSのComunityイメージ Mappings: RancherAMI: # v1.1.3-hvm-1 ap-northeast-1: OsOnly: ami-a873edce ap-northeast-2: OsOnly: ami-e8af0f86 ap-south-1: OsOnly: ami-74a0f41b 8 / 16
  9. 9. AWS EC2でのcloud-init設定⽅法 UserData: Fn::Base64: !Sub | #cloud-config rancher: services: rancher-server: image: rancher/server restart: unless-stopped ports: - 8080:8080 runcmd: - echo `date` "runcmd" >> /var/lib/rancher/rancher_server_setup.log Serverサービス起動、コマンド実⾏ 9 / 16
  10. 10. 起動スクリプトにファイル書き込み write_files: - path: /etc/rc.local permissions: "0755" owner: root content: | #!/bin/bash echo `date` "rc.local before" >> /var/lib/rancher/rancher_server_setup.log nohup /var/lib/rancher/rancher_server_setup.sh & echo `date` "rc.local after" >> /var/lib/rancher/rancher_server_setup.log - path: /var/lib/rancher/rancher_server_setup.sh permissions: "0755" owner: root content: | #!/bin/bash echo `date` "rancher_server_setup before" >> /var/lib/rancher/rancher_server_setup.log if [ ! -e /var/lib/rancher/rancher_server_setup.done ]; then echo `date` "rancher_server_setup.done false" >> /var/lib/rancher/rancher_server_setup.log wait-for-docker #>> /var/lib/rancher/rancher_server_setup.log echo `date` "wait-for-docker done" >> /var/lib/rancher/rancher_server_setup.log セットアップスクリプトの実⾏を記述 10 / 16
  11. 11. セットアップ判定、サービス起動待ち #!/bin/bash echo `date` "rancher_server_setup before" >> /var/lib/rancher/rancher_server_setup.log if [ ! -e /var/lib/rancher/rancher_server_setup.done ]; then echo `date` "rancher_server_setup.done false" >> /var/lib/rancher/rancher_server_setup.log wait-for-docker #>> /var/lib/rancher/rancher_server_setup.log echo `date` "wait-for-docker done" >> /var/lib/rancher/rancher_server_setup.log cnt="0" while [ "$cnt" = "0" ] do sleep 5 cnt=`docker ps | grep "rancher/server" | grep -v grep | wc -l` #echo `date` "rancher/server check: $cnt" >> /var/lib/rancher/rancher_server_setup.log done echo `date` "rancher/server check done" >> /var/lib/rancher/rancher_server_setup.log wait-for-dockerは UserDocker起動待ち 11 / 16
  12. 12. API実⾏許可待ち、ホスト登録URL設定 cnt="0" while [ "$cnt" = "0" ] do sleep 5 cnt=`wget https://localhost:8080/v2-beta/registrationtokens -qO - | jq -r .links.self | wc -l` #echo `date` "registrationtokens check: $cnt" >> /var/lib/rancher/rancher_server_setup.log done echo `date` "registrationtokens done" >> /var/lib/rancher/rancher_server_setup.log sip=`wget http://169.254.169.254/latest/meta-data/public-ipv4 -qO -` docker run --rm appropriate/curl -ik 'https://'$sip':8080/v2-beta/settings/api.host' -X PUT -H 'content-type: application/json' -d '{"id":"api.host","type":"activeSetting","baseType":"setting","name":"api.host", "activeValue":null,"inDb":false,"source":null,"value":"http://'$sip':8080"}' >> /var/lib/rancher/curl.log echo `date` "api host setting done" >> /var/lib/rancher/rancher_server_setup.log RancherOSのwgetはbusyboxコマンドで GETしか出来ないのでcurlのイメージ使⽤ 12 / 16
  13. 13. Customホスト設定、エージェント実⾏ docker run --rm appropriate/curl -ik 'https://'$sip':8080/v2-beta/projects/1a5/registrationtoken' -X POST -H 'content-type: application/json' -d '{"type":"registrationToken"}' echo `date` "custom host registrationtoken done" >> /var/lib/rancher/rancher_server_setup.log cnt="0" while [ "$cnt" = "0" ] do sleep 5 cnt=`wget https://localhost:8080/v2-beta/registrationtokens -qO - | jq -r .data[].command | wc -l` #echo `date` "run agent command check: $cnt" >> /var/lib/rancher/rancher_server_setup.log done cmd=`wget https://localhost:8080/v2-beta/registrationtokens -qO - | jq -r .data[].command` $cmd echo `date` "run agent command done" >> /var/lib/rancher/rancher_server_setup.log touch /var/lib/rancher/rancher_server_setup.done 完了したらセットアップ済ファイル作成 13 / 16
  14. 14. それでは実際に⾛らせてみましょう! 14 / 16
  15. 15. c4.8xlargeで 3〜4分くらいで起動 # cat rancher_server_setup.log Thu Jan 18 06:37:26 UTC 2018 runcmd Thu Jan 18 06:37:26 UTC 2018 rc.local before Thu Jan 18 06:37:26 UTC 2018 rc.local after Thu Jan 18 06:37:26 UTC 2018 rancher_server_setup before Thu Jan 18 06:37:26 UTC 2018 rancher_server_setup.done false Thu Jan 18 06:37:30 UTC 2018 wait-for-docker done Thu Jan 18 06:38:10 UTC 2018 rancher/server check done Thu Jan 18 06:38:50 UTC 2018 registrationtokens done Thu Jan 18 06:38:55 UTC 2018 api host setting done Thu Jan 18 06:38:56 UTC 2018 custom host registrationtoken done Thu Jan 18 06:39:18 UTC 2018 run agent command done Thu Jan 18 06:39:18 UTC 2018 rancher_server_setup after m4.largeなら 7〜8分といった所 15 / 16
  16. 16. まとめ cloud-initを使えば Rancherの ほとんどの初期設定を⾃動化出来る RancherOSはサービスがコンテナで Serverやカスタムサービスも起動可能 AWS CLIから実⾏すれば Rancherは コマンド⼀撃でセットアップ可能! 16 / 16

×