Kubernetes を使ってサービスを加速させる取り組み

Kubernetes を使ってサービスを加速させる取り組み

YAP(achimon)C::Asia Hachioji 2016 mid in Shinagawa
2016/07/03 日本マイクロソフト

Kubernetes 導入について話をしました

Bc1e4b3a33fe6718f50285d1c1f53feb?s=128

Kodai Sakabe

July 03, 2016
Tweet

Transcript

  1. 2.

    "CPVUNF w ࡔ෦޿େ w !LPVEBJJJ w 8BOUFEMZͷΠϯϑϥΤϯδχΞ w %PDLFSΛ1SPEVDUJPOͰ࢖͍ଓ͚Δཧ༝ w

    IUUQTXXXXBOUFEMZDPNDPNQBOJFT XBOUFEMZQPTU@BSUJDMFT w 8"/5&%-:5&$)#00,
  2. 4.

    w ճ݄  w ճि  w ճ೔  w

    ճ೔  w ճ࣌  w ճ࣌ IUUQXXXQVCMJDLFZKQCMPHBNB[PO@BXT@SFJOWFOUEBZ@BNIUNM
  3. 6.

    w ϲ݄  w िؒ  w ೔  w

    ࣌ؒ  w EFQMPZͱಉ͡  w ͦ΋ͦ΋ΠϯϑϥνʔϜ ج൫νʔϜ ʹ͓ئ͍͠ͳ͍ͱ͍͚ͳ͍
  4. 9.

    $PEFXJOTBSHVNFOUT w νʔϜͰ࣌ؒ.5(͢ΔͳΒDPEFΛॻ͍ͯݕূ͠Α͏ w ΤϯδχΞͷ৔߹ w ݶΒΕͨ৘ใͰܾஅΛͯ͠ɺલʹਐΜͰ͍Δ͔ w ԾઆΛ͋Ε͜Εߟ͑ΔΑΓɺ·ͣϓϩτλΠϓΛ࡞ͬͯૣֶ͘श͍ͯ͠Δ͔ w

    Ӧۀͷ৔߹ w ࣗ෼Ͱྑ͍ػೳ͕ු͔Μ͔ͩΒΤϯδχΞʹཔΉͷͰ͸ͳ͘ w اըॻΛॻ͍ͯձࣾΛճͬͯɺࣾఔ౓Λ֬໿ͯ͠ɺ͜ΕͳΒߦ͚ΔͱࢥͬͨΒΤϯδχΞʹཔΉ͜ͱ ͕ग़དྷΔ͔
  5. 16.

    Ͳ͏͢Δʁ w ͭ͸։ൃνʔϜΈ͍ͨʹਓΛ૿΍͢ w ΋͏ͭ͸ΠϯϑϥνʔϜͷྗΛ͋͛Δ͜ͱ w ਓ͋ͨΓͲΕ͘Β͍ͷαʔόɺͲΕ͘Β͍ͷछྨͷΞϓϦɺͲΕ͘Β͍ͷϢʔβ਺Λ ࢧ͍͑ͯΔ͔ w ྫສ୆ͷαʔόΛສਓͰݟ͍ͯͨΒ݁ہਓ୆ͷྗ͔͠ͳ͍

    w ୆ͷαʔόʔਓͰݟ͍ͯͨ΋ͷΛɺ୆ݟΕΔͱྗ্͕ͬͨ w ೥ͷ࣌఺Ͱ'BDFCPPLͷΠϯϑϥνʔϜ͸Θ͔ͣਓ΄ͲͰສ୆Λ؅ཧ 8BOUFEMZ͸ޙऀΛ໨ࢦ͢
  6. 23.
  7. 26.

    %PVH.D*MSPZ 6/*9૑࢝ऀͷਓͰQJQFͷൃ໌ऀ 6/*9఩ֶ w 5IJTJTUIF6OJYQIJMPTPQIZ w 8SJUFQSPHSBNTUIBUEPPOFUIJOHBOEEPJUXFMM w 8SJUFQSPHSBNTUPXPSLUPHFUIFS w

    8SJUFQSPHSBNTUPIBOEMFUFYUTUSFBNT CFDBVTFUIBUJTBVOJWFSTBMJOUFSGBDF w <༁> w 6/*9ͷ఩ֶ͸ҎԼͰ͋Δɻ w ͭͷϓϩάϥϜ͕ɺͭͷ໾ׂʹઐ೦͢Δɻ w ෳ਺ͷϓϩάϥϜ͸ڠௐͯ͠ಇ͘ɻ w ϓϩάϥϜ͸൚༻తΠϯλʔϑΣΠεͰ͋Δඪ४ೖग़ྗΛѻ͏ɻ
  8. 27.

    .JLF(BODBS[ 98JOEPX4ZTUFNઃܭνʔϜͷҰһ ͷ6/*9఩ֶ w 4NBMMJTCFBVUJGVM w .BLFFBDIQSPHSBNEPPOFUIJOHXFMM w #VJMEBQSPUPUZQFBTTPPOBTQPTTJCMF w

    <༁> w খ͍͞΋ͷ͸ඒ͍͠ w ͭͷϓϩάϥϜ͸୯७ͳͭͷػೳΛߦ͏ w ͳΔ΂͘ૣ͘ϓϩτλΠϓΛ࡞੒ͤΑ
  9. 30.

    w %FQMPZͱ1SPWJTJPOJOHUPPMઃఆ w Ϧιʔε௥Ճ &-#3%4"VUP4DBMF֤SPMF͝ͱͷ&$  w αʔϏεىಈͱӡ༻ηοςΟϯά w ಈ࡞֬ೝ

    w .POJUPSJOH௥Ճ /FX3FMJD1BHFSEVUZ)POFZCBEHFS%BUBEPH  w ඞཁͰ͋Ε͹ΫϥελϦϯά༻ҙ w "ࢯʮखॱͱ΍Δ͜ͱ͕ଟ͗ͯ͢ແཧͰͨ͠ʯ
  10. 31.

    ղܾ͍ͨ͜͠ͱ w ͱʹ͔͘ϦϦʔεՄೳʹͳΔ·Ͱ͕͔͔࣌ؒΔ w ෳࡶ͗ͯ͢࡞ۀग़དྷΔͷ͕ݶΒΕͨϝϯόʔͷΈ w ৽͍͠ϑϨʔϜϫʔΫΛؾܰʹೖΕΕͳ͍ w EFQMPZͷQJQFMJOF͕ݻఆԽ͞ΕͯΔ w

    ม͍͑ͨ৔߹͸ɺΠϯϑϥνʔϜʹґཔ͢Δ͔͠ͳ͍ w ͦΕ SBJMT Ҏ֎ͷCBDLFOEαʔϏε͸౎౓ݕ౼ w JOTUBODFDPOUBJOFSͷ੍໿ .POJUPSJOHܥ͸আ͘
  11. 36.

    ΫϥελϦϯάͰԿ͕ग़དྷΔ w .BQ3FEVDF͕ಈ͔ͤΔΠϯϑϥΛ࡞ͬͯ͘ΕͱݴΘΕͨ࣌ʹͺͬͱ࡞ΕΔ w .BQ3FEVDFͷλεΫ͸୆͙Β͍͸࠷௿࢖͏΋ͷ w ճͷղੳʹ࢖͍͍ͨΑ͏ͳ͙͢ऴΘΔλεΫ w ΤϥʔΛىͯ͜͠΋ɺผͷͱ͜ΖͰ૸Βͤ௚͢ͱ͔͕؆୯ʹͰ͖Δ w

    99༻ʹϚγϯΛཱͯɺ࣍͸::༻ʹϚγϯΛཱͯɺ࣍͸Έ͍ͨͳ͜ͱ͕ͳ ͍ ʮԿ͕ԿॲͰಈ͍͍ͯΔ͔Λҙ͍ࣝͯ͠ͳ͚Ε͹ͳΒͳ͍ੈքʯ͔ΒʮԿ͕ಈ͍͍ͯΔ͔͚ͩҙ͍ࣝͯ͠Ε͹ྑ͍ੈքʯ
  12. 46.

    ,VCFSOFUFT5JQT w %BUB4UPSFΛ͋·Γஔ͔ͳ͍ํ͕ྑ͍ w ྫ͑͹&MBTUJD4FBSDIΛݐ͍ͯͨ৔߹ɺ&#4ͷBUUBDIEFUBDI͕ࣗಈͰ͖ͳ͍ͷͰJOTUBODFΛ݁ہݻఆ͠ͳ͍ͱ͍͚ͳ͍ w DMVTUFSΛ࡞ΔͨΊͷUPPMʹ͋·Γ࣌ؒΛׂ͔ͳ͍ w ௨ৗۀ຿ͱ౤ࢿͷ݉Ͷ߹͍ 

    w ެࣜͷTDSJQUΛ࢖ͬͯΔ IUUQTHJUIVCDPNLVCFSOFUFTLVCFSOFUFTCMPCNBTUFSDMVTUFSBXTPQUJPOTNE w LVCSFOFUFT.FFUVQWPMͰίΞϝϯόʔΑΓ,VCFSOUFTͷ؀ڥΛ࡞ΔUPPMͷվળʹࠓޙऔΓ૊ΉΒ͍͠ w EPDLFSJNBHFͰMBUFTUΛ࢖Θͳ͍ w LVCFSOFUFTͰ͸ಉ͡JNBHFUBH͸ۃྗDBDIFΛ࢖͏ w %PO`UVTFIPTU1PSU w IUUQLVCFSOFUFTJPEPDTVTFSHVJEFDPOpHCFTUQSBDUJDFT
  13. 47.

    ,FZ %FTDSJQUJPO %FGBVMU &YBNQMF /6.@/0%&4 ԿݸOPEFΛཱͯΔ͔   ,6#&3/&5&4@1307*%&3 BXTʹ͢Δ

    HDF BXT "84@%&'"6-5@130'*-& DSFEFOUJBMTͷ໊લΛࢦఆ͢Δ EFGBVMU EFW ,6#&@"84@;0/& [POFΛܾΊΔ VTXFTUB BQOPSUIFBTUC "84@*."(& JNBHFΛࢦఆ͍ͨ͠৔߹ར༻͢Δ   "84@4@3&(*0/ LVCFSOFUFTͷNFUBEBUBΛ4ʹอଘ͢ΔϦʔδϣϯઌɻ VTFBTU BQOPSUIFBTU "84@4@#6$,&5 LVCFSOFUFTͷNFUBEBUBΛ4ʹอଘ͢Δόέοτઌɻ˞ LVCFSOFUFTTUBHJOH\QSPKFDU@IBTI^ LVCFSOFUFTCVDLFURB ,6#&@"84@*/45"/$&@13&'*9 JOTUBODFͷ໊લΛ௥هͰ͖Δɻ DMVTUFS໊͕ʮ,6#&3/&5&4@1307*%&3 @ ,6#&@"84@*/45"/$&@13&'*9ʯͰ࡞ΒΕΔɻ˞ LVCFSOFUFT LTRB ."45&3@4*;& /0%&@4*;& OPEFͷ਺ͰNBTUFSͷTJ[F͕͋Δఔ౓ࣗಈͰܾΊͯ͘ΕΔ͕ɺJOTUBODFUZQFΛࢦఆ͢Δ͜ͱ΋Ͱ͖Δɻ  DMBSHF ,6#&@&/"#-&@/0%&@16#-*$@* 1 OPEFʹ͍ͭͯQVCMJDJQΛ࢖͏͔બ୒͢Δɻ 536& 536& %0$,&3@4503"(& CUSGT BVGT EFWJDFNBQQFS BVGTOPMWNΛࢦఆͰ͖Δɻ BVGT BVGT ,6#&@04@%*453*#65*0/ $PSF04Ͱ͸OPEFؚΊͨDMVTUFSߏங͕TVQQPSU֎ʹؾΛ͚ͭΔɻ KFTTJF͸OPEFͱNBTUFSͰDMVTUFS͕૊·ΕΔɻ KFTTJF KFTTJF ,6#&@71$@$*%3@#"4& DMVTUFSΛߏங͢Δ71$ͷ·ͰͷωοτϫʔΫΛࢦఆͰ͖Δɻ˞   /0/@."426&3"%&@$*%3 ͜ͷൣғ֎ͷ*1ΞυϨε΁ͷτϥϑΟοΫ͸ɺ*1ϚεΧϨʔυΛ࢖༻͢Δɻ˞   4&37*$&@$-645&3@*1@3"/(& ެ։༻ͷ*1ɻ˞   %/4@4&37&3@*1 ಺෦%/4ͷ*1ΛܾΊΔɻ˞   ."45&3@*1@3"/(& .BTUFSͱͳΔ*1ൣғͷܾΊΔɻ˞   $-645&3@*1@3"/(& $MVTUFSൣғΛࢦఆ͢Δɻ˞   ."45&3@%*4,@4*;& FUDEͷEBUB΍伴͕֨ೲ͞Ε͍ͯΔɻ (#   ."45&3@3005@%*4,@4*;& EPDLFSJNBHF౳͕ೖΔɻ (#   /0%&@3005@%*4,@4*;& EPDLFSJNBHF౳͕ೖΔɻ (#   ˞ͭΊͷΫϥελΛߏங͍ͨ͠৔߹ʹɺ஋Λม͑ΔɻFYQPSU౳ͯ͠PQUJPOΛࢦఆͯ͠ɺAXHFUR0IUUQTHFULTJPcCBTIA
  14. 50.

    4FDSFUʹ"1*@,&:Λొ࿥ EBUBEPHͳͲͰ࢖༻͞ΕΔ"1*@,&:Λ(JUͷ؅ཧԼʹೖΕͳ͍Α͏ʹ ,VCFSOFUFTͷTFDSFUʹొ࿥͢Δ $ kubectl create secret generic dd-agent --from-literal=api-key=YYYYYYYYYYYYYYYYYYYYc

    secret "dd-agent" created $ cat examples/dd-agent/dd-agent.yaml ///////////////////// env: - name: API_KEY valueFrom: secretKeyRef: name: dd-agent key: api-key ////////////////////
  15. 51.

    )FBMUIDIFDL w LVCFSOFUFT্Ͱ͸EFGBVMUͰίϯςφͷϓϩηεΛνΣοΫ͓ͯ͠Γɺࣦഊ͍ͯ͠Ε͹SFTUBSU͢Δ w SFBEJOFTT1SPCF w ॳճىಈ࣌ʹ΢ΥʔϜΞοϓ͕ඞཁͳΞϓϦέʔγϣϯͷ৔߹ɺSFBEJOFTT1SPCFΛ࢖͏ w 4VDDFTTʹͳͬͨޙɺ࣮ࡍʹUSB⒏DΛड෇͚Δ w

    MJWFOFTT1SPCF w ίϯςφ͕ੜ͖͍ͯΔͲ͏͔ݟΔ w -JWFOFTT1SPCF͕'BJMVSFͷ৔߹ɺ3FTUBSU1PMJDZͷର৅ͱͳΓLVCFMFU͔ΒίϯςφΛLJMM͢Δ IUUQLVCFSOFUFTJPEPDTVTFSHVJEFXBMLUISPVHILTIFBMUIDIFDLJOH
  16. 52.

    "QQMJDBUJPO)FBMUI$IFDLJOH IUUQ(FUΛ࢖ͬͨྫ apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx spec:

    template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 livenessProbe: httpGet: # Path to probe; should be cheap, but representative of typical behavior path: /index.html port: 80 initialDelaySeconds: 30 timeoutSeconds: 1
  17. 53.

    "QQMJDBUJPO)FBMUI$IFDLJOH FYFDΛ࢖ͬͨྫ apiVersion: v1 kind: Pod metadata: labels: test: liveness

    name: liveness-exec spec: containers: - args: - /bin/sh - -c - echo ok > /tmp/health; sleep 10; rm -rf /tmp/health; sleep 600 image: gcr.io/google_containers/busybox livenessProbe: exec: command: - cat - /tmp/health initialDelaySeconds: 15 timeoutSeconds: 1 name: liveness
  18. 54.

    -JGFDZDMF ,VCFSOFUFTͰ͸EFMFUFͨ͠ࡍʹɺ4*(5&3.͕ૹΒΕΔɻ UFSNJOBUJPO(SBDF1FSJPE4FDPOET EFGBVMUT ΑΓ௕͍৔߹͸ɺ4*(,*--͕ૹΒΕΔɻ apiVersion: extensions/v1beta1 kind: Deployment metadata:

    name: nginx spec: template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 lifecycle: preStop: exec: # SIGTERM triggers a quick exit; gracefully terminate instead command: ["/usr/sbin/nginx","-s","quit"]
  19. 55.

    EPUFOWΛTFDSFUͰ؅ཧ EUBOLTFD # Sercet Λ࡞Δ(key=value΋߹Θͤͯ࡞Δ) $ kubectl create secret generic

    test --from-literal=key1=supersecret --from-literal=key2=topsecret # ֬ೝํ๏(get) $ k8sec list NAMETYPEKEY VALUE 
 ### ઃఆํ๏(set/unset) $ k8sec set test key=value 
 ### manifest ʹ͔͘ env: - name: USERNAME valueFrom: secretKeyRef: name:test key: key1 - name: PASSWORD valueFrom: secretKeyRef: name: test key: key2
  20. 57.

    4FSWJDF w QSPYZΛ࡞Δ w LVCFDUMBQQMZGEFQMPZNFOUZBNM w QSPYZ༻ͷTFSWJDFΛ࡞Δ w LVCFDUMBQQMZGTWDZBNM kind:

    Service spec: ports: - port: 80 type: LoadBalancer selector: app: nginx Node ɾɾɾɾɾɾɾɾɾɾɾɾɾɾɾ 63- ֤/PEF*199999 LVCFQSPYZ MBCFM BQQOHJOY
  21. 59.

    4DIFNFมߋͳ͠ͷEFQMPZ w <DVSSFOUDPMPS> w LVCFEFTDSJCFͷTFMFDUFSͰࠓͷDPMPSΛ஌Δ w LVCFEFTDSJCFTWDSBJMTŠOBNFTQBDFSBJMT w <EFQMPZNFOU> w

    LVCFFEJU͢Δ w LVCFFEJUEFQMPZNFOUCMVFOBNFTQBDFSBJMT MBCFMT OBNFBQQ BQQSBJMT DPMPSHSFFO MBCFMT OBNFBQQ BQQSBJMT DPMPSCMVF LVCFQSPYZ LJOE4FSWJDF UZQF/PEF1PSU QPSUT OBNFSBJMT QPSU UBSHFU1PSU TFMFDUPS OBNFBQQ BQQSBJMT DPMPSHSFFO SBJMT 3PMMJOH6QEBUF LVCFFEJUEFQMPZNFOUCMVF
  22. 60.

    $PMPSDIFDL DPMPSHSFFOͱͳ͍ͬͯΔͨΊɺݱࡏ͸HSFFO $ kube describe svc rails --namespace=rails Name: rails

    Namespace: rails Labels: app=rails,name=app Selector: app=rails,color=green,name=app Type: NodePort IP: 100.64.166.49 Port: rails 3000/TCP NodePort: rails 31257/TCP Endpoints: 100.66.0.8:3000,100.66.4.6:3000 Session Affinity: None No events.
  23. 61.

    3PMMJOH6QEBUF FEJUPS͕։͔ΕΔͷͰɺJNBHFUBHΛมߋ͢Δ $ kube edit deployment green --namespace=myspace deployment "green"

    edited # watch Option Ͱ֬ೝग़དྷΔ $ kube get po --namespace=rails -w NAME READY STATUS RESTARTS AGE green-3776542877-v3t1u 1/1 Running 0 3m green-3776542877-u2yoy 1/1 Running 0 3m green-191853544-v3ol2 1/1 Terminating 0 20d green-191853544-v3ol2 0/1 Terminating 0 20d
  24. 62.

    4XJUDI w <TXUJDIDPMPS> w TFMFDUPSͷDPMPSͷWBMVFΛCMVFʹม͑Δ w LVCFDUMFEJUTWDSBJMTOBNFTQBDFSBJMT MBCFMT OBNFBQQ BQQSBJMT

    DPMPSHSFFO MBCFMT OBNFBQQ BQQSBJMT DPMPSCMVF LVCFQSPYZ LJOE4FSWJDF UZQF/PEF1PSU QPSUT OBNFSBJMT QPSU UBSHFU1PSU TFMFDUPS OBNFBQQ BQQSBJMT DPMPSCMVF SBJMT LVCFFEJUTWDSBJMT TFMFDUPSͷDPMPSΛมߋ
  25. 63.

    4XJUDI $ kube describe svc rails --namespace=rails Name: rails Namespace:

    rails Labels: app=rails,name=app Selector: app=rails,color=green,name=app Type: NodePort IP: 100.64.166.49 Port: rails 3000/TCP NodePort: rails 31257/TCP Endpoints: 100.66.0.8:3000,100.66.4.6:3000 Session Affinity: None $ kube edit svc rails --namespace=rails service "rails" edited $ kube describe svc rails --namespace=rails Name: rails Namespace: rails Labels: app=rails,name=app Selector: app=rails,color=blue,name=app Type: NodePort IP: 100.64.166.49 Port: golang 3000/TCP NodePort: golang 31257/TCP Endpoints: 100.66.1.5:3000,100.66.4.8:3000 Session Affinity: None
  26. 64.

    LVCFDUM७ਖ਼ͷखؒ w ·ͩ·ͩख͕ؒଟ͍ w UBHҰཡ͕ݟ͍ͨTUBUVTΈ͍ͨͳ෺͕ݟ͍ͨ w Ϩεϙϯε͕ΠϯϑϥدΓͷදࣔͰ΋͏গ͠ݟ΍͍ͨ͘͢͠ w &EJUPSΛ։͘ͷ͕໘౗ w

    ALVCFDUMHFUTWDSBJMTPZBNTcTFEFT HSFFO CMVF HcLVCFDUMBQQMZGAͱ ͍͏ख΋͋Δ w NBOJGFTUϑΝΠϧΛͲ͏༻ҙ͢Δ͔