Upgrade to Pro — share decks privately, control downloads, hide ads and more …

このConsulがすごい!/consul is great!

このConsulがすごい!/consul is great!

中央線Meetup#1 での発表資料です
https://chuoline.connpass.com/event/93685/

Yuichi Kiri

August 03, 2018
Tweet

More Decks by Yuichi Kiri

Other Decks in Technology

Transcript

  1. ConsulͰԿ͕Ͱ͖ΔΜ΍ • Ϋϥελߏஙɺϝϯόγοϓ؅ཧ • ϔϧενΣοΫ • αʔϏεσΟεΧόϦ • K/V ετΞ

    • ෼ࢄΠϕϯτॲཧ • ෼ࢄϩοΫ/෼ࢄηϚϑΥ • αʔϏεؒ௨৴ͷAuth(N/Z)΍௨৴҉߸Խ (mTLS) • ଞProductͱ૊Έ߹ͤΔͱ͞ΒͳΔՄೳੑ
  2. Consul͕ඞཁͱͳΔഎܠ • ಈతͳϊʔυ௥Ճ/࡟আ͕ΨϯΨϯى͜Γ
 ͯΜ΍ΘΜ΍͢Δ • MicroServices • Auto Scaling •

    Node ނো • ͦΜͳ؀ڥͰ͋ͬͯ΋ϊʔυ͸
 ڠௐ͠ԿΒ͔ͷ໨తΛՌͨ͞Ͷ͹ͳΒ͵ զʑͱ͓ͳ͡Ͱ͸
  3. ΞʔΩςΫνϟ • Agentܕɻ֤ϊʔυʹΠϯετʔϧ͢Δɻ • Agentʹ͸ServerɺClientͷ2छྨ͕ଘࡏ͢Δ • Client͸: • ࣗϊʔυࣗ਎ͱࣗϊʔυ্ͷαʔϏεΛ؂ࢹ •

    GossipingʹΑΓಈతʹΫϥελΛߏ੒ • 1Ϋϥελ͋ͨΓ਺୆ʙ਺ઍor਺ສ୆ • Server͸: • Client͔Βͷ৘ใΛ΋ͱʹΫϥελϨϕϧͷ৘ใΛ·ͱΊͯอ࣋ • 1Ϋϥελ͋ͨΓ3୆͋Δ͍͸5୆͕جຊ /PEF JOTUBMM
  4. $POTVM$MVTUFS ED ΞʔΩςΫνϟ - Server/Client • RaftΛ࢖͍ΫϥελશମʹؔΘΔσʔλΛ
 ੔߹ੑͷऔΕͨܗͰอ࣋ɾڞ༗ $POTVM$MVTUFS ED

    $POTVM4FSWFST $POTVM"HFOUT • Agent͕Service/NodeͷϔϧενΣοΫ • Service/Nodeεςʔλεɺϝϯόγοϓतड • ΫϥελϨϕϧͷ৘ใ͸Serverʹ໰߹ͤ $POTVM4FSWFST $POTVM"HFOUT • Raft: ίϯηϯαεϓϩτίϧ • αʔόؒͰͷ౤ථʹΑΓϦʔμʔΛબग़ • Ϧʔμʔ͸αʔόͷ߹ҙΛܦͨΫϥελ಺ͷ ঢ়ଶ/৘ใΛଞαʔόʹϨϓϦέʔγϣϯ • ผDC্ͷαʔόͱ΋GossipingͰ৘ใΛڞ༗ ɾ/PEF4FSWJDF4UBUVT ɾ,FZ7BMVF4UPSF ɾFUD - (PTTJQJOH 48*. 3BGU - "OUJ&OUSPQZ ਪ঑ʙDMVTUFS
  5. ΞʔΩςΫνϟ - ໰͍߹ΘͤͷྲྀΕ $POTVM$MVTUFS ED $POTVM4FSWFST $POTVM"HFOUT - - ೚ҙͷαʔόʹ໰͍߹Θͤ

    Ϧʔμʔʹ໰͍߹Θͤ • ໰͍߹Θͤʹ͸Ϧʔμʔ͕ճ౴ • ڧ੔߹ੑΛอ࣋ • ҰํͰΫϥελϫΠυͷσʔλ͸ଞαʔ ό΋อ࣋ • RaftͷϨϓϦέʔγϣϯܦ༝ • Ϧʔμʔ͕ࢮΜͰ΋੾ସ͑Ε͹ྑ͍ ͨͩ͠ɺαʔϏεσΟεΧόϦ͸
 σϑΥͩͱ݁Ռ੔߹ੑɻ͜ͷ͋ͨΓ͸ઃఆՄ /P41P' DPOTVMLWHFUSFEJTDPOpHDPOO
  6. αʔϏεͷࢮ׆৘ใͷڞ༗ • ໰୊ • web͔ΒaccountαʔϏεʹAPI call͍ͨ͠ • web͸ͲͷIPΞυϨεʹAPIΛૹΕ͹ྑ͍͔ • ͨͩ͠

    accountαʔϏε਺͸ࣗಈతʹ૿ݮ͢Δ΋ͷͱ͢Δ XFC BDDPVOU BDDPVOU BDDPVOU -#ͷ7*1 -# ɾ-#͕41P'ʹͳͬͪΌ͏ʜ ˠ-#Λ)"ʹ͢Δͱ·ͨ৭ʑ໘౗ʹʜ  ɾBDDPVOUαʔϏε͕૿ݮͨ͠ͱ͖ͷ-#ϧʔϧ൓өͲ͏͢Δʜ ɾଞαʔϏε͕௥Ճ͞Εͨͱ͖-#͸଱͑ΒΕΔʜ
  7. αʔϏεͷࢮ׆৘ใͷڞ༗ • ໰୊ • web͔ΒaccountαʔϏεʹAPI call͍ͨ͠ • web͸ͲͷIPΞυϨεʹAPIΛૹΕ͹ྑ͍͔ • ͨͩ͠

    accountαʔϏε਺͸ࣗಈతʹ૿ݮ͢Δ΋ͷͱ͢Δ XFC BDDPVOU BDDPVOU BDDPVOU BDDPVOUTFSWJDFDPOTVM  "HFOUʹzBDDPVOUzαʔϏεͷଘࡏΛొ࿥  IFBMUIZͳαʔϏεΛ࣋ͭϊʔυΛ%/4)551ͰDPOTVMʹ໰߹ͤ EJH TIPSUBDDPVOUTFSWJDFDPOTVM    3PVOE3PCJOͰฦͬͯ͘ΔͷͰɺෛՙ෼ࢄ΋༰қ
  8. 1. Prepared QueryΛొ࿥
 
 
 
 
 
 
 2.

    Prepared QueryΛར༻ͯ͠DNS lookup DVSMŠSFRVFTU1045ŠEBUBb\ l/BNFzlQHGBJMPWFSz  l4FSWJDFzlQHz  l'BJM0WFSz\ l%BUBDFOUFSTz<lEDz lEDz>  ^ ^`IUUQWRVFSZ ೚ҙͷϊʔυʹొ࿥͓͚ͯ͠͹ɺ
 Ϋϥελશମʹ఻ൖ͢Δ EJH TIPSUQHGBJMPWFSRVFSZDPOTVM %JTDPWFSZઌ  ϩʔΧϧͳ%$಺ͷ1(  ED಺ͷ1(  ED಺ͷ1( 1SFQBSFE2VFSZͷ5FNQMBUFػೳΛ࢖͑͹ɺ Ұʑ֤αʔϏε༻ʹ2VFSZΛॻ͔ͳͯ͘΋ͭͷ 2VFSZ͚ͩͰ'BJMPWFSΛ࣮ݱͰ͖·͢ Service Discoveryͷ໰߹ͤΫΤϦΛڞ༗
  9. ઃఆ৘ใͷڞ༗ • ໰୊ • ಈతʹ૿ݮ͢ΔϊʔυؒͰઃఆ৘ใΛڞ༗͍ͨ͠ • ઃఆ৘ใ͕มߋ͞ΕͨΒ௨஌ͯ͠΄͍͠ DPOTVMLWQVUSFEJTDPOpHDPOO - ,FZ7BMVFͷ஋Λڞ༗

    DPOTVMLWHFUSFEJTDPOpHDPOO DPOTVMXBUDIUZQFLFZQSFpY
 QSFpYSFEJTTDSJQUTIBOEMFSTI SFEJT഑Լͷ஋͕มΘͬͨΒ
 ϋϯυϥ࣮ߦ
  10. ϩοΫͷڞ༗ • ໰୊ • N୆ͷMWΛৗ࣌Քಈ͍͕ͤͨ͞ɺ
 Մ༻ੑͷͨΊʹ͞Βʹ1୆ΛHot Standby͓͖͍ͤͯͨ͞ DPOTVMMPDLOMPDLLFZ`QBUIUPNXTUBSUTIIPHF` .8ىಈ .8ىಈ

    ϩοΫղআ͸ɺϊʔυͷނো-FBEFSมߋ౳Ͱൃੜɻ αϒϓϩηεʹ͸4*(5&3.ˠඵˠ4*(,*-- PO-JOVY DPOTVMMPDLOMPDLLFZ`QBUIUPNXTUBSUTIIPHF` DPOTVMMPDLOMPDLLFZ`QBUIUPNXTUBSUTIIPHF` ϩοΫ͕֎ΕΔ·Ͱ଴ػɻ
 ֎ΕͨλΠϛϯάͰίϚϯυ࣮ߦɻ ϩοΫऔಘ༻ͷΩʔ ϩοΫऔಘ੒ޭ࣌ʹ࣮ߦ͞ΕΔίϚϯυ
  11. ূ໌ॻ/ൿີ伴ͷڞ༗ • ໰୊ • αʔϏεؒ௨৴Λ҉߸Խ͢Δͱͱ΋ʹೝূɾೝՄΛߦ͍͍ͨ
 (TLS encryption + auth(n|z)) TJEFDBS

    QSPYZ "1*$BMMUP
 BOPUIFSTFSWJDF DFSU BVUI[ TJEFDBS QSPYZ DFSU BVUI[ XJUIFODSZQUJPO 
 \DMJFOU TFSWFS^DFSU  $POTVM$POOFDUΛ༗ޮԽ  αʔϏεؒ௨৴ͷϧʔϧઃఆ DPOTVMJOUFOUJPODSFBUFBMMPXXFCBDDPVOU ɾ$POTVM͕ূ໌ॻͱϧʔϧ *OUFOUJPO Λڞ༗ ɾ$POTVMʹରԠͨ͠1SPYZ͕ྑ͠ͳʹ
 5-4ɺ"VUI[Λѻͬͯ͘ΕΔ XFC BDDPVOU
  12. ·ͱΊ • Consul͸෼ࢄ؀ڥͰ৘ใڞ༗Λߦ͏ͨΊͷπʔϧ • ڞ༗͢Δ৘ใʹΑͬͯϢʔεέʔεͷ੄໺͕޿ ͕Δ • ୯ମͰ΋: • Service

    Discovery, KV Store(Deployment, Feature Toggle, etc.), Service Mesh, etc. • ଞϓϩμΫτͱͷ૊Έ߹Θͤ: • consul-template, consul-esm, fabio, envoy