2014年のchefとinfrastructure as code
DESCRIPTION
JTF2014のセッションスライドです。TRANSCRIPT
![Page 1: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/1.jpg)
2014年のChefと Infrastructure as code
JTF2014 (June 22 2014) @sawanoboly (HiganWoks LLC)
![Page 2: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/2.jpg)
運営組織
2
• 業務執行社員をつとめる合同会社
• アプリケーションのためのプラットフォーム構築/運用自動化をテーマにした活動を担当
• http://opsrock.in 共同開発・運営
• Chefをはじめ、Infrastracture as Code関連を主に取り扱うソリューションを提供
• 導入支援・トレーニングも
![Page 3: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/3.jpg)
本日のお話• Chefをひと通り解説
• Chef本ベース+補足など !
• 近頃のChef関連 Update
• Chef-Zero, ChefDK, Chef-Metal..
• local_mode, local_template
3
![Page 4: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/4.jpg)
Chefの本
![Page 5: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/5.jpg)
5
ちなみに買った人ー?
![Page 6: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/6.jpg)
6
![Page 7: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/7.jpg)
7
![Page 8: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/8.jpg)
Chef書籍:Chef活用ガイドより
![Page 9: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/9.jpg)
Chefとは• 米Chef社(Chef Software, Inc.)が開発保守
する構成管理のフレームワーク
• 旧社名Opscode
• Infrastructure as codeの一部で利用
9
![Page 10: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/10.jpg)
Infrastructure as code• 背景に、APIコールでサーバインスタンスが
調達できる環境
• インフラを抽象化し、設計、実装といったプロセスをコードで管理しよう
• テストなど、アプリ開発の優れた手法を取り入れ
• バージョン管理を行い、Githubなどでコードを中心にしたコミュニケーション
10
![Page 11: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/11.jpg)
Chef社が提唱する10の原則のうち 構成管理ツールに求められる要素抜粋• 拡張に対応しやすい
• 変更や増強、改良が容易。
• 再現できる
• 環境の再生や複製は重要。
• 冪等性を持つ
• 必要な時にだけ実行
• 収束性がある
• 宣言し、その通りの状態へ。
11
![Page 12: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/12.jpg)
Chefの基本機能• ノード(サーバ)情報の収集
• 収集した情報の集約
• コンフィグレーション
• Cookbook/Recipeにリソースを定義し、収集したノード情報を元に状態を収束する
• ほか、いわゆるプロビジョニング
12
![Page 13: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/13.jpg)
情報収集&集約
![Page 14: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/14.jpg)
情報収集イメージ (Server/Client構成)
14
書籍:Chef活用ガイドより
![Page 15: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/15.jpg)
情報収集ライブラリ OHAI
書籍:Chef活用ガイドより
![Page 16: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/16.jpg)
Ohaiの役割• (非常に)泥臭くプラットフォームを判別し、
Chef実行時にハード・OS情報を提供。
• 拡張は容易、さらに単体でも使えます。
16書籍:Chef活用ガイドより
![Page 17: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/17.jpg)
Ohai単独の例
17
![Page 18: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/18.jpg)
Chef-Server書籍:Chef活用ガイドより
![Page 19: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/19.jpg)
Chef-Serverの概要• ノード情報の集約
• ポリシー配布のハブ
• 作業端末とノードの中間に位置
• 基本的にメタデータの保持
• 種類は2つ
• Open Source Chef
• Enterprise Chef
19
![Page 20: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/20.jpg)
最近は導入の敷居も低い• OpenSource版のインストールはパッケージ
で簡単。
• 管理コマンド`chef-server-ctl`
20
![Page 21: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/21.jpg)
Chef-Clientの一味 (Chef-Client, Chef-Solo, Chef-
apply, Chef-Shell)書籍:Chef活用ガイドより
![Page 22: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/22.jpg)
Chef-Clientの役割• Chef-Server(または任意のデータストア)への
Node情報アップロード
• Nodeの収束
• 実行状況と結果のレポート !
• 意外と多機能なエージェントとして作られています
• サーバに色々入れるの嫌か、インスタンスのインターフェースとして受け入れるかは自由
22
![Page 23: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/23.jpg)
Chef-Clientの種類• Chef-Client: 前項の全て
• Chef-Shell: 対話式
• Cookbook開発やデバックに
• Knifeによる一括更新
• Chef-Apply: 簡易実行
• Chef-Solo: 主にプロビジョナ用途
• handler等の活用で、Chef-Server環境に劣らない連携も可能
23
![Page 24: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/24.jpg)
プロビジョナとしての Chefと連携するツール
![Page 25: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/25.jpg)
仮想環境ユーティリティ
25
Test-KitchenはChef公式ツール
![Page 26: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/26.jpg)
プロビジョナの相互適用例• VagrantまたはTest-KitchenでCookbookの
開発とテストを実施
• プロビジョナ部分をpackerで実行し、AMIやVagrant boxにして配布
26
![Page 27: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/27.jpg)
*aaS• ※こちらはコンフィグレーションも含む
27
![Page 28: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/28.jpg)
Workstation (& Git(hub))
書籍:Chef活用ガイドより
![Page 29: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/29.jpg)
書籍:Chef活用ガイドより
![Page 30: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/30.jpg)
Infrastructure as code 導入のキモWorkstatonとリポジトリ
30
引用:Infrastructure as Code - naoyaのはてなダイアリー <http://d.hatena.ne.jp/naoya/20131215/1387090668>
![Page 31: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/31.jpg)
Seach Data Bags Environment
Role Cookbook & LWRP
書籍:Chef活用ガイドより書籍:Chef活用ガイドより
書籍:Chef活用ガイドより
![Page 32: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/32.jpg)
細かすぎるので省略。 でも一点だけ
![Page 33: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/33.jpg)
役割ベースの設計• Chefを活用する場合、システムが提供する
サービスを役割で分け、レイヤを積み重ねるように設計するのが良いです。 !
• 『ベテランシステム管理者であれば、既にサーバーをロールベースでスクリプト化しているはず』- [翻訳] Dockerについてよくある勘違い(http://techracho.bpsinc.jp/hachi8833/2014_06_16/17982) より
33
![Page 34: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/34.jpg)
Enterprise Chefの 追加要素
![Page 35: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/35.jpg)
Reporting• Chef-Clientの実行状況を記録。
35
![Page 36: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/36.jpg)
Push jobs
36
• サーバからPushでジョブ実行、成否の管理。
![Page 37: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/37.jpg)
ただしChef-Clientの ソースは共通
![Page 38: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/38.jpg)
多少工夫すれば OpenSource版でも同様の実装はOK
38
![Page 39: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/39.jpg)
2014年のChef (※2013モノも含む)
![Page 40: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/40.jpg)
2014年のChef傾向• Chef-Server構成
• 検証しやすさを向上
• Chef-Client系
• 単体でもServer相当機能
• 極シンプルな実行をサポート
• WorkStation系
• セットアップ負担の軽減をめざす
• ? Infrastructure as code推進系
• リソース定義の概念を広げる
40
![Page 41: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/41.jpg)
Chef-Zero
Server構成を検証しやすくする (揮発性)軽量Chef-Server
![Page 42: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/42.jpg)
Chef-Zeroの特徴• Chef-Server APIのCRUDを全てサポート
• ただし認証は全部通る
• オンメモリでデータの永続性は無い
• 消しやすさ = テスト向き
42
![Page 43: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/43.jpg)
Chef-Zeroの活用• Test-KitchenでChef-Server対応Cookbook
の動作確認に
• Vagrantのchef-clientプロビジョナと組み合わせてクラスタ向けCookbookの動作確認
• vagrant-pluginもあるがやや環境依存
• 専用VMを当てるかローカルで上げ下げするのが無難
43
![Page 44: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/44.jpg)
Chef Development Kit (Chef-DK)
WorkStation環境の簡単セットアップ Omnibusの系譜
![Page 45: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/45.jpg)
Chef-DKとは• ChefのCookbook開発とServer管理ツール
一式をパッケージ形式にしたもの。
• 新規: chefコマンド
• Mac OS X, Linux対応、WindowsはComing Soon…
• (現状)公式おすすめのワークフローを実践するツールとの連携設定済み
• Test-Kitchen, Barkshelf, Foodcritic等
45
![Page 46: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/46.jpg)
で、DK使ったほうがいいの?• 古参からするとあまり必要でないかも
• Rubyプロジェクト管理手法がわかっていればとくに
• Chef系以外にもインテグレーションしたいツールは沢山ある
• チームで環境を揃えたい等にはよいのかも
• あと、DKパッケージは妙にデカイ
46
![Page 47: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/47.jpg)
Chef-Client Local Mode
Chef-RepoをServerレスで
![Page 48: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/48.jpg)
Local Mode• chef-client -z / knife -z
• knife solo っぽい形態
• ローカルファイルシステムにあるChef-Repoを元にChef-Clientを実行
• nodes/以下に自分及び他nodeの情報を設置して、Searchが可能
• knifeでServer環境と同一の操作体系
48
![Page 49: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/49.jpg)
Chef-Metal
LWRPで片鱗、 よりInfrastructure as codeへ
リソース解釈を拡大
![Page 50: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/50.jpg)
50
http://qiita.com/inokappa/items/78c31bdf0b415ed2d954
http://qiita.com/TsuyoshiUshio@github/items/180a54994df57a1d08d3
![Page 51: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/51.jpg)
51
![Page 52: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/52.jpg)
Chefで扱うリソースの拡大• 従来の一般的なChefリソース
• 単一Node上の要素(file, service, package等)
!
• Chef-Metalで扱うリソース
• IaaS上のコンピュータリソース
• 台数などの要素を状態管理
52
![Page 53: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/53.jpg)
補足:状態を持つリソースについて
• recipe = 単一ノードへの変更という概念はわかりやすさ優先のミスリード
• 構造化されたデータを取得し、定義通りになるアクションを(主にRubyで)実行できるならば、なんでも管理対象
• LWRPでは以前から実践されている
• コミュニティCookbook等では、LWRPとして『リソース=クラスタ』という状態管理するものも存在
• MongoDB, RabbitMQ, ElasticSerach等
53
![Page 54: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/54.jpg)
Chef-Metalの対応• 基本はコンピュータリソースの調達
(ノードの増減とレシピの適用)
• vagrant
• fog (マルチクラウド対応ライブラリ)
• ec2, digitaloceanなどPublic IaaS
• *Stackな Private IaaS
• 国内ベンダ 『Sakura no Cloud』
54
![Page 55: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/55.jpg)
fog補足• fogの対象はコンピュート系リソース以外にも
及ぶ
• ストレージ
• Network
• NameServiceなどなど !
• 複数クラウドを対象に可搬性のあるCloudFormation (にするつもりかもしれない)
55
![Page 56: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/56.jpg)
Local Template
ちょっとChef、をとても便利に 地味ながら使える機能拡張
![Page 57: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/57.jpg)
予備知識:Chef-Apply• Recipeを次の形式で実行
• 標準入力
• 単一ファイル
• 簡単な設定変更やバッチ処理に
• Cookbookのお決まり事が不要
57
![Page 58: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/58.jpg)
58
![Page 59: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/59.jpg)
local trueでの挙動は単純• local => false
• erbテンプレートのサーチ対象
• レシピと同じCookbook
• 任意Cookbook内のtemplates/ !
• local => true
• 絶対パス
• Chef-Applyがtemplateを気軽に扱えるように
59
![Page 60: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/60.jpg)
2014年のChef傾向まとめ• Chef-Server構成
• 検証しやすさを向上 (Chef-Zero, Local Mode)
• Chef-Client系
• 単体でもServer相当機能 (Local Mode)
• 極シンプルな実行をサポート (Local Template)
• WorkStation系
• セットアップ負担の軽減をめざす (Chef-DK)
• ? Infrastructure as code推進系
• リソース定義の概念を広げる (Chef-Metal)
60
![Page 61: 2014年のChefとInfrastructure as code](https://reader033.vdocuments.mx/reader033/viewer/2022052900/555e8000d8b42a41328b50c4/html5/thumbnails/61.jpg)
終