Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PackerとAnsibleでコンパクトに始めるInfrastructure as Code
Search
co-sche
February 10, 2017
Technology
0
260
PackerとAnsibleでコンパクトに始めるInfrastructure as Code
AMIの手運用に潜む罠と、Packer・Ansibleのレイヤー感のお話
co-sche
February 10, 2017
Tweet
Share
More Decks by co-sche
See All by co-sche
DynamoDBとBloomFilterのムフフなカンケイ
co_sche
0
1.4k
Other Decks in Technology
See All in Technology
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
260
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
200
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
260
MLOps の現場から
asei
6
640
C++26 エラー性動作
faithandbrave
2
730
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
160
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
3
2.3k
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
380
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Building an army of robots
kneath
302
44k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Speed Design
sergeychernyshev
25
670
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Visualization
eitanlees
146
15k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Transcript
PackerͱAnsibleͰ ίϯύΫτʹ࢝ΊΔ Infrastructure as Code
ࣗݾհ • ฏদ ߛయ (ͻΒ·ͭ ͜͏͚͢) • ϓϩάϥϚʔ / ΞʔΩςΫτ
/ ΫϥυΠϯϑϥ • 33ɺ185ɺ74ɺ140ɺ100 • ͓͔͞ͳͨΒΕͳ͍
AWS͔ͭͬͯ·͔͢ʁ ࠓճɺAWSʹԙ͍ͯͷϚγʔϯΠϝʔδͰ ͋ΔɺAMIͷཧʹϑΥʔΧε͓ͨ͠Ͱ ͢ɻ
͘͡ 1. ΠϛϡʔλϒϧΠϯϑϥετϥΫνϟ 2. AMIӡ༻͋Δ͋Δ 3. Ansible 4. Packer 5.
Packer + Ansible
Πϛϡʔλϒϧ ΠϯϑϥετϥΫνϟ
ΠϛϡʔλϒϧΠϯϑϥετ ϥΫνϟ • ෆมͳΠϯϑϥ • ࡞ͬͨΒߏɾઃఆͳͲͷมߋΛՃ͑ͳ͍ • มߋ͕ඞཁͳ߹ • ৽͍͠ͷΛ࡞ͬͯ
• ೖΕସ͑ͯ • ݹ͍ͷΛࣺͯΔ • ͍ࣺͯ
ΞϓϦέʔγϣϯαʔό Πϛϡʔλϒϧ • αʔόΠϯελϯεΛ͍ࣺͯΔ • ΫϥυΠϯϑϥͰͷΦʔτεέʔϦϯά ͳͲʹݟΒΕΔ͍ࣺͯͬΓɺAMIͳͲ ͷϚγϯΠϝʔδ͕͋Δ͔Βͦ͜ͳͤΔۀ
AMIͷӡ༻
AMIͷӡ༻ Πϯϑϥ୲ʮLDAPͱ͔ೖΕͨɺϕʔεͷAMI࡞ͬͨͰʔʯ ৴αʔό୲ʮScalaೖΕͳͳʯ ͚ࣾཧ໘୲ʮஸ৴αʔόͷ͕ScalaೖͬͯΔͬͨ͠Ζʯ Τϥʔϩάαʔό୲ʮΞϓϦNodeJS͚Ͳɺࢹͱ͔ͷઃఆΖΖ ೖͬͯΔ͠ɺ৴αʔόͷͭͬͨΖʯ ཧళ͚ཧ໘୲ʮNodeJSαʔόΛϕʔεAMI͔ΒͪΌΜͱͭ͘Ζʯ ϝσΟΞ͚ཧ໘୲ʮNodeJS͠ɺཧళཧ໘ͷίϐʔ͢Δ͔ʯ
AMIͷӡ༻ • ࣮ࡍҰͷίϐʔˍՃηοτΞοϓͰࡁ·ͳͯ͘ɺ 1ίϯϙʔωϯτʹ͖ͭෳճͷAMI࡞͕ߦΘΕΔ • ֤୲͕ࢥ͍ࢥ͍ͷࣗݾॴ༗AMIΛબͼɺࢥ͍ࢥ͍ͷ ՃηοτΞοϓΛߦ͍ɺ৽ͨͳࣗݾॴ༗AMIΛੜͯ͠ ͍Δ
AMIͷӡ༻ • ͜ͷӡ༻Λ1΄Ͳଓ͚͖ͯͨ • ౿ΜͰ͠·ͬͨɺए͍ۙ͘͠কདྷ౿ΉͰ ͋Ζ͏ཕݪͱͳΔ͕େ͖͚ͯ͘2 छྨ
AMIͷ
AMIͷ AMI͕ࢬ͔ΕͱΛ܁Γฦ͠ɺηΩϡϦ ςΟΞοϓσʔτͳͲͷڞ௨Ͱඞཁͳϝϯς φϯεͷࡍʹͷAMIΛ୳͠ճΒͳ͚Ε ͳΒͳ͘ͳΔ
AMIͷ ྫ͑… Πϯϑϥ୲ʮࢹΛStackDriverʹ͠Αʯ ʮJavaೖͬͯΔͭʹJMXͷΤʔδΣϯτೖΕͳͳʯ ʮҰݸҰݸݟͯճΔΜ͔…ʯ ʮ֤ίϯϙʔωϯτͷ࠷৽ͷAMIͲΕ…ʯ ʮͳΜ͜ΕɺJavaೖͬͯΔ͚Ͳϓϩηε্͕ͬͯͳ͍Μ͚(ࠔ)ʯ ʮ͏͑͑Θɻ֤୲͔ͬ͠ΓೖΕͱ͍ͯʔʯ
AMIͷ • ཧෆೳ • ͕ɺՃͷηοτΞοϓͳΒ·ͩྗٕͰͳ Μͱ͔ͳΔ
ൿͷλϨ
ൿͷλϨ ܧ͗͠ܧ͗͠ͰηοτΞοϓΛߦ͓ͬͯ Γɺ࡞ۀΛͨ͠ຊਓ͔ͦ͠ͷతɾ༰ɾ֬ ೝࣄ߲ΛΒͳ͍
ൿͷλϨ ྫ͑… AWS ʮ͋Μͨͱ͜ͷͬͱΔAmazon Linux ͷόʔδϣϯɺαϙʔτΕΔ͔ΒೖΕସ͑ʔ ɻʯ
ൿͷλϨ બࢶ • ৽͍͠όʔδϣϯͷAmazon LinuxͷϕʔεAMIʹηοτ Ξοϓ͢͠ • ԿೖΕΕࠓ·Ͱ௨Γಈ͘Μ͚ͬ • ࠓͷAMIͷAmazon
LinuxͷόʔδϣϯΛ্͛Δ • Կͷಈ࡞Λ֬ೝ͢Ε͑͑Μ͚ͬ
ൿͷλϨ ֤୲ʮʮʮ ʘ(^o^)ʗ ʯʯʯ
ল (ݴ͍༁) • զʑͷϓϩδΣΫτͰɺAWSͷར༻ͦͷͷ ͕ٕज़తઓͩͬͨ • AMIͱͬͱ͚ɺಉ͡Πϯελϯε͍͘ΒͰ࡞ ΕΔ͡ΌΜʂͰຫ৺ͯ͠ɺAMIͦͷͷͷཧΛ ૄ͔ʹͯͨ͠
AMIΠϛϡʔλϒϧʹ • ͱ͍ͬͯɺAMIͦͦΠϛϡʔλϒϧͩ • ӡ༻͕Πϛϡʔλϒϧ͡Όͳ͍ (͍ࣺͯͰ͖ͳ͍) • AMI͍ࣺͯͰ͖ΔΑ͏ʹ • AMIͷηοτΞοϓɺίʔυͱͯ͠දݱͯ͠όʔ
δϣϯཧ
Ansible
AMIηοτΞοϓͷྲྀΕΛ͓ ͞Β͍ 1. ݩʹͳΔAMI͔ΒΠϯελϯεΛىಈ 2. ىಈͨ͠ΠϯελϯεʹsshͰೖͬͯɺͳΜ͔ΜΠϯ ετʔϧɾϑΝΠϧͷஔɾઃఆ 3. ΠϯελϯεͷεφοϓγϣοτΛࡱΔ 4.
εφοϓγϣοτΛAMIͱͯ͠ొ 5. ΠϯελϯεΛআ
AMIηοτΞοϓͷྲྀΕΛ͓ ͞Β͍ 1. ݩʹͳΔAMI͔ΒΠϯελϯεΛىಈ 2. ىಈͨ͠ΠϯελϯεʹsshͰೖͬͯɺͳΜ͔ΜΠϯ ετʔϧɾϑΝΠϧͷஔɾઃఆ 3. ΠϯελϯεͷεφοϓγϣοτΛࡱΔ 4.
εφοϓγϣοτΛAMIͱͯ͠ొ 5. ΠϯελϯεΛআ
αʔόߏཧ • 2ͰͬͯΔ͜ͱࢥ͍͖ͬΓαʔόͷߏཧ ͳͷͰɺͦΕʹదͨ͠ιϦϡʔγϣϯΛ͏ • લͷϓϩδΣΫτ(ΦϯϓϨཧαʔό)ͰChef Λ͚ͬͯͨͲɺྲྀߦΓʹྲྀ͞Ε͍͢ࢲ AnsibleΛબ
None
Ansible • ༷ʑͳOSʹରԠͨ͠ɺߏཧιϦϡʔγϣϯ • ղઆෆཁ • σΟϨΫτϦϨΠΞτͳͲɺެࣜϕετϓϥΫςΟεʹ ै͏ • શͯͷηοτΞοϓࣗݾॴ༗Ͱͳ͘Amazonॴ༗ͷૉͷ
Amazon Linuxʹߦ͏ͷͰɺႈੑ͋·Γҙࣝ͠ͳ͍Ͱ͍͍
ιʔεެ։
Packer
AMIηοτΞοϓͷྲྀΕΛ͓ ͞Β͍ 1. ݩʹͳΔAMI͔ΒΠϯελϯεΛىಈ 2. ىಈͨ͠ΠϯελϯεʹsshͰೖͬͯɺͳΜ͔ΜΠϯ ετʔϧɾϑΝΠϧͷஔɾઃఆ 3. ΠϯελϯεͷεφοϓγϣοτΛࡱΔ 4.
εφοϓγϣοτΛAMIͱͯ͠ొ 5. ΠϯελϯεΛআ
AMIηοτΞοϓͷྲྀΕΛ͓ ͞Β͍ 1. ݩʹͳΔAMI͔ΒΠϯελϯεΛىಈ 2. ىಈͨ͠ΠϯελϯεʹsshͰೖͬͯɺͳΜ͔ΜΠϯ ετʔϧɾϑΝΠϧͷஔɾઃఆ 3. ΠϯελϯεͷεφοϓγϣοτΛࡱΔ 4.
εφοϓγϣοτΛAMIͱͯ͠ొ 5. ΠϯελϯεΛআ
AMIͷऔΓճ͠ AWSͷϚωίϯ͔ΒϙνϙνΔͷγϯυ ͍
Packer • ༷ʑͳԾԽϓϥοτϑΥʔϜʹରԠͨ͠ɺ ϚγϯΠϝʔδੜιϦϡʔγϣϯ • ϚγϯΠϝʔδʹͳΜ͔ͯ͠৽͍͠ϚγϯΠ ϝʔδΛੜ͢Δ͜ͱʹಛԽ • 1,3,4,5Λ·ͱΊͯ໘Έͯ͘ΕΔ
Packer • 2ʹؔͯ͠PackerͰ·͔ͳ͑Δ͕ɺ୯ମ ͰshεΫϦϓτͷ࣮ߦͷΈՄೳ • Provisionerͱͯ͠AnsibleΛબͰ͖Δɻ • ઃఆ؆୯
ιʔεެ։
Packer + Ansible
Packer + Ansible • Ұɺҙ͖͢ϙΠϯτ • ௨ৗɺpacker build packer.json Ͱ͓̺
• ෆ༻ҙͳΞοϓσʔτΛ͙ʹɺyumͷϦϙ δτϦόʔδϣϯΛݻఆ͠ͳ͚ΕͳΒͳ͍
Packer + Ansible • yumϦϙδτϦͷόʔδϣϯΛݻఆ͢Δʹɺ Ұඞཁ • AMIͷ໊લ͔ΒόʔδϣϯΛऔΓग़ͯ͠มͱ ͯ͠Ҿ͖ճ͠ɺ/etc/cloud/cloud.cfgʹຒΊࠐΉ
ιʔεެ։
AMI࡞ʹඞཁͳखॱ 4063$&@".*BNJYYYYYYYYa 1-":#00,BBBBBBBa CVJMETI Ҏ্
݁Ռ • AMI࡞ͷશͯͷηοτΞοϓ༰Λίʔυʹམ ͱ͢͜ͱͰɺൿͷλϨԽΛࢭΊΒΕͨ • ↑ͷηοτΞοϓ༰ΛৗʹૉͷAmazon Linux AMIʹྲྀ͢Α͏ϧʔϧ͚͢Δ͜ͱͰɺAMIͷ ԽΛࢭΊΒΕͨ
·ͱΊ • AMIͷཧΛखӡ༻Ͱߦ͏͜ͱͦͷͷ͕ কདྷͷཕʹͳΔ • AMIͷԽɺൿͷλϨԽͱ͍͏ཕϙΠ ϯτΛɺPackerͱAnsibleͰճආ͠Α͏
Have a nice Machine Image Life!
͋Γ͕ͱ͏͍͟͝·ͨ͠