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

はてなリモートインターン2021 Kubernetes 講義資料

Hatena
October 08, 2021

はてなリモートインターン2021 Kubernetes 講義資料

Hatena

October 08, 2021
Tweet

More Decks by Hatena

Other Decks in Technology

Transcript

  1. Kubernetes
    IBUFOBJOUFSO

    View full-size slide

  2. 舅䄕磆☭
    ˝ JENBTBZPTV
    ˝ 䇗僖⪌炘
    ˝ ؤ٤ط٤صوٚشعنؚ٭ّכ
    لةؾتوٚشعنؚ٭ّס43&
    ך׌

    View full-size slide

  3. 铺紶ס⯥מ
    ׆ס铺紶⫂ךעLVCFSOFUFTסـ٤ث؛٤؅㲔产׌׾סך
    ׆׿־׼䣆⩕ס.BDמص٭ٜ؅ؕ٤تع٭ٜ׊ױ׌

    View full-size slide

  4. ؕ٤تع٭ٜ
    ˝ %PDLFS
    %PDLFSGPS.BD
    ˝ CSFXJOTUBMM
    % brew update
    % brew install kubectl kustomize minikube mysql skaffold

    View full-size slide

  5. ׆ס铺紶ך㰢؆ך׮׊ַ׆כ
    ˝ ם׏LVCFSOFUFT؅⮵榫׌׾ס־յLVCFSOFUFT؅⮵榫׌׾׆כ
    סْٛشع؅䣆؅Ⳃ־׊םֿ׼䚉׋׮׊ַ
    ˝ ⺱侇מLVCFSOFUFTס邾ꥭ׈׵䚉׋י׮׊ׂיյ舅骰ך䤗软鹟㲊
    ׌׾侇ס免乢כ׊י׮׊ַ

    View full-size slide

  6. ,VCFSOFUFTכע
    ˝ LVCFSOFUFT LT
    ˝ ؤ٤طػ؛٭آتعٝ٭ب٘٤סג״סخنعؘؗؓ
    ˝ ؤ٤طػסظوٞؕյ؛٭عتآ٭ٛ٤ءםלס畘杼؅舅Ⳃ⴫׌׾ג
    ״סوٚشعنؚ٭ّ
    ˝ 舅⯥ס擻杼ُب٤┕מوٚشعنؚ٭ّ؅啶疣׌׾׆כ׵⺎耆
    ˝ قهٛشؠؠٚؗغך׵وٚشعنؚ٭ֿّ䬠❠׈׿יַ׾
    ˝ "84&,4 ($1(,& "[VSF",4

    View full-size slide

  7. ם׏,VCFSOFUFT؅✳ֹס־
    ˝ وٞرؠب٘٤梪㗞ךؤ٤طػ؅Ⳃ־׌
    ˝ 냕⺎榫䓪؅㲔杯׌׾ג״מؤ٤طػ؛٭آتعٝ٭ب٘٤ֿ
    䑒釐
    ˝ ؤ٤طػסَ٭ذلٛطؔ؅孨־׊י냕ئؕؠٜםꝧ氦
    ˝ ؓوٛآ٭ب٘٤յؕ٤نٚꝴסٕٝؕ٭؅LVCFSOFUFTֿ䥩
    霄⴫׊יׂ׿׾ג״斻玮׊גꝧ氦٬鷞榫ֿ⺎耆

    View full-size slide

  8. ם׏,VCFSOFUFT؅✳ֹס־
    ˝ ؤ٤طػ؛٭آتعٝ٭ب٘٤סظنؒؠعتذ٤ر٭غ
    ˝ 䇗㍑סٛٛ٭تئؕؠٜס╈ך䷉ャ׈׿י׀ג
    ˝ $MPVE/BUJWF$PNQVUJOH'PVOEBUJPO $/$'
    כַֹؤِٖؼ
    طؔס䡗捘
    ˝ LVCFSOFUFTꝧ氦؅ئَ٭ع׌׾ג״סخنعؘؗؓ׵㛡丗㰆㏇
    ˝ 㛻䣆قهٛشؠؠٚؗغךסLVCFSOFUFTئ٭لتס氦辐

    View full-size slide

  9. LVCFSOFUFTך⛰ֿך׀׾ס־
    ˝ 㲚銧氳ם啶䡗畘杼 *OGSBTUSVDUVSFBT$PEF

    ˝ ؤ٤طػ鿥糋סتآةٖ٭ٛ٤ء
    ˝ 靷蕔⮆丆ئ٭لتظؔت؜فٛ٭
    ˝ جٜنك٭ٛ٤ء
    ˝ ؛٭عتآ٭ٛ٤ء

    View full-size slide

  10. ,VCFSOFUFTס啶䡗
    

    View full-size slide

  11. $MVTUFS
    ˝ ُتذ٭ؿ٭غכ٠٭؜٭ؿ٭غך啶䡗׈׿׾
    ˝ ُتذ٭ؿ٭غ
    ˝ ؤ٤عٞ٭ٜوٝ٭٤
    ˝ ؠٚتذ؅畘杼؅䥵䎎
    ˝ قهٛشؠؠٚؗغךעُؾ٭ةغמ䬠❠׈׿׾
    ˝ ٠٭؜٭ؿ٭غ
    ˝ ظ٭ذوٝ٭٤
    ˝ ؤ٤طػ؅㲔车׌׾ג״סؤ٤مٖ٭طؔ٤ءٛ
    خ٭تס꥗ױ׽
    ˝ 邾丗סOPEF؅玮ה┕ׅ׾׆כך냕⺎榫䓪؅䐂׾׆
    כֿך׀׾
    

    View full-size slide

  12. /PEF
    ˝ 擻杼PS♞䘶סئ٭ف٭
    ˝ 邾丗ס1PE ؤ٤طػ
    ؅㲔车׌׾ג״סؤ٤
    مٖ٭طؔ٤ءٛخ٭ت
    ˝ LVCFMFUֿ颯Ⳃ׊יַיُتذ٭ؿ٭غס
    "1*כ׷׽כ׽؅׌׾
    ˝ /PEFע邾丗⺏ך颯Ⳃ׈׿ؠٚؗغ梪㗞ךע
    تآ٭ٜ׌׾☼磝ײ؅㵵⪌׊יַ׾㕙⺬ֿ
    㛡ַ
    

    View full-size slide

  13. 1PE
    ˝ ظوٞؕס僃㵸ⶡ⛣
    ˝ 1PEעח♓┕סؤ٤طػ־׼啶䡗׈׿׾
    ˝ ْؕ٤סؓوٛآ٭ب٘٤ؤ٤طػכא׿؅
    遨Ⲃ׌׾ئهؤ٤طػ־׼啶䡗׈׿׾
    

    View full-size slide

  14. 1PEסظاؕ٤قذ٭٤
    ˝ ئؕغ؜٭قذ٭٤
    ˝ ئهؤ٤طػעْؕ٤ؤ٤ط
    ػ؅ئَ٭ع׌׾׻ֹם䏔Ⱏ
    ؅䥵ֹ
    ˝ ❆
    1SPYZ ٞء鬇鴜 泃釱
    ؙ٭ةؘ٤ع
    

    View full-size slide

  15. ,VCFSOFUFTסٛخ٭ت
    

    View full-size slide

  16. LVCFSOFUFTסٛخ٭تכ؜طإٛ
    ˝ 8PSLMPBET
    ؤ٤طػס㲔车מ꞊׌׾ٛخ٭ت
    ˝ 4FSWJDF
    ؤ٤طػ؅㛙鼧⪜ꝧ׌׾׻ֹםؙ٤غَؕ٤ع؅䬠❠׌׾ٛخ٭ت
    ˝ $POH4UPSBHF
    錃㲊٬嚀㳡䗯㕔٬姧禈⴫ٍٖٛ٭ّםלמ꞊׌׾ٛخ٭ت
    ˝ $MVTUFS
    ج؞ٖٛطؔ׷ؠؚ٭ذםלמ꞊׌׾ٛخ٭ت
    ˝ .FUBEBUB
    ؠٚتذ⫂ס☽סٛخ٭ت؅䳩⛼׌׾ג״סٛخ٭ت
    /BNFTQBDFכַֹ♞䘶氳םؠٚتذס⮆ꦕ嚀耆
    

    View full-size slide

  17. 8PSLMPBET؜طإٛ
    ˝ 1PE
    ח♓┕סؤ٤طػ־׼啶䡗׈׿יַ׾
    1PE⫂מ⻠ױ׿׾ؤ٤طػע⺱׋ؾشع٠٭
    ؠ⫂מ㰆㏇׊⺱┉*1؅䧏ח
    ˝ 3FQMJDBTFU
    1PEסٝوٛ؜؅⛼䡗׊י䧗㲊׊ג丗ס1PE
    ؅禴䧏׌׾ جٜنك٭ٛ٤ء

    ⺱׋ؓوٛآ٭ب٘٤ֿⳂ⛼׊יַ׾邾丗ס
    1PEֿ姡䇖מ㷣ꝧ׈׿׾
    ˝ %FQMPZNFOU
    邾丗ס3FQMJDBTFU؅畘杼׊יٞ٭ٛ٤ءؓش
    وظ٭ع׷ٞ٭ٜفشؠםל؅⺎耆מ׌׾
    

    View full-size slide

  18. 8PSLMPBET؜طإٛ
    ☪㍑סـ٤ث؛٤ךע⮵榫ם׊
    ˝ +PC
    ؤ٤طػ؅⮵榫׊י٠٤؛نס⭚杼؅㲔车׈׎׾ٛخ٭ت
    ˝ $SPO+PC
    تآةٖ٭ٜ׈׿ג侇ꝴמKPC؅㲔车׌׾ٛخ٭ت
    

    View full-size slide

  19. 4FSWJDF؜طإٛ
    ؤ٤طػ؅㛙鼧⪜ꝧ׌׾׻ֹםؙ٤غَؕ٤ع؅䬠❠׌׾ٛخ٭ت
    ⹨⟓׊גعٚنؔشؠ؅邾丗ס1PEמٞ٭غفٚ٤ب٤ء׌׾
    ˝ 4FSWJDF
    ˝ -ٞ٭غفٚ٤ئ
    ˝ ئ٭لتظؔت؜فٛ
    ˝ *OHSFTT
    ˝ -ٞ٭غفٚ٤ئ
    

    View full-size slide

  20. LVCFSOFUFTؠٚتذ⫂ס鵟⟓
    ˝ ⺱׋1PE⫂סؤ٤طػמ鵟⟓׌׾㕙⺬עMPDBMIPTU㲌מ鵟⟓׌׾
    ˝ ⮯ס1PE⫂סؤ٤طػמ鵟⟓׌׾㕙⺬ע1PEס*1㲌מ鵟⟓׌׾
    ˝ *1㲌ס鵟⟓ע⺎耆דֿؓوٛآ٭ب٘٤־׼*1؅䧗㲊׌׾כ㲔
    鷞榫┕ך鐐갭ֿ氦榟׌׾
    ˝ 1PEס*1ע1PEֿ⪌׿僀؂׾䈱מ樟ם׾*1ֿⰟ׽䎎י׼׿׾
    ˝ 1PEֿ⢥塛׊ג㕙⺬מئ٭لت了ֿ氦榟׌׾
    

    View full-size slide

  21. 4FSWJDFٞ٭غفٚ٤ئ
    ˝ 邾丗ס1PEמ㵚׌׾ٞ٭غفٚ٤ب٤ء؅舅Ⳃ氳מ啶䡗׌׾
    ˝ ٞ٭غفٚ٤ب٤ء 靷蕔⮆丆
    ס⪌׽⹾כם׾ؙ٤غَؕ٤ع؅䬠❠
    ˝ ؙ٤غَؕ٤عמעⶡ┉ס♞䘶*1ֿⰟ׽䎎י׼׿׾
    ˝ ؙ٤غَؕ٤عס牊걉ע榫鵍מ׻זי喋չ
    ˝ $MVTUFS*1 ⫂鼧⺸ׄ

    ˝ /PEF1PSU 㛙鼧⺸ׄ

    ˝ -PBE#BMBODFS 㛙鼧⺸ׄ

    ˝ FUD
    

    View full-size slide

  22. 4FSWJDFئ٭لتظؔت؜فٛ
    ˝ Ⳃ氳מ1PEֿ⪌׿僀؂׾ؠٚتذ٭⫂ך䗯㕔؅
    氧ꎰյ氦釤׌׾ג״ס☼磝ײ
    ˝ ؠٚتذ⫂%/4ס⮵榫ֿ䫟㝢׈׿יַ׾
    ˝ ٞ٭غفٚ٤ب٤ءס⪌׽⹾כם׾ؙ٤غَ
    ؕ٤ع؅ؠٚتذ⫂%/4מ舅Ⳃ氳מ氧ꎰ׌׾
    ˝ BDDPVOUئ٭لتעaccount.hatena-
    intern-2021.svc.cluster.localכַֹ
    䎬䌋ך%/4"ٝؤ٭غמⰟ׽䎎י׼׿׾
    

    View full-size slide

  23. *OHSFTT
    ˝ *OHSFTT
    ˝ -סٞ٭غفٚ٤ئ
    ˝ 㲔逷ע喋չ "84"-# ($1($-# ؠٚتذ⫂/HJOY

    ˝ )5514ס磙珷
    ˝ *OHSFTT$POUSPMMFS
    ˝ *OHSFTTٛخ٭تֿ氧ꎰ׈׿׾כ┕鋗㲔逷ס㲔⛮؅⛼䡗׌׾
    ˝ "84-PBE#BMBODFS$POUSPMMFS
    ˝ (,&*OHSFTT$POUSPMMFS
    ˝ /HJOY*OHSFTT$POUSPMMFS
    

    View full-size slide

  24. ٛخ٭ت畘杼מחַי
    

    View full-size slide

  25. .BOJGFTU
    ˝ ٛخ٭ت㲊紶ֿ傴־׿ג:".-
    ˝ kubectl apply -f מ׻זיLTؠٚتذמ
    鸵榫
    ˝ ׆׿מ׻׽㲚銧氳םؤ٭غמ׻׾畘杼ֿ⺎耆כם׾
    ˝ *OGSBTUSVDUVSFBT$PEF
    

    View full-size slide

  26. ٛخ٭ت⯆꡾
    ˝ 1PEמ㵚׊יⰟ׽䎎י׾$16׷ْٓٛס⯆꡾؅车ֹ׆כֿך׀
    ׾
    ˝ $16ؤؓ W$16
    ؅N NJMMJDPSFT
    כ׊י䧗㲊
    ˝ 釐姲כ⯆꡾
    ˝ ┖꡾כ┕꡾؅䧗㲊ך׀׾
    ˝ ؿ٭غמ1PE؅鿥糋׌׾꤀מ縒䜡׈׿׾
    

    View full-size slide

  27. ىٜتزؘشؠ
    ˝ 1PEֿ塜׊ׂⳂ⛼׊יַ׾־澬鏀׌׾ג״ס☼磝ײ
    ˝ -JWFOFTT1SPCF
    ˝ ؓوٛآ٭ب٘٤ֿ颯Ⳃ׊յؤ٤طػֿ塜׊ׂⳂ⛼׊יַ׾־לֹ־
    ˝ زؘشؠֿ鵟׼ם־זגכ׀ע1PE؅⫋颯Ⳃ׌׾
    ˝ 3FBEJOFTT1SPCF
    ˝ 1PEֿٛؠؙتع؅⹨ׄ♀ׄ׾嶖⤓ֿך׀יַ׾־לֹ־
    ˝ زؘشؠֿ鵟זגכ׀מعٚنؔشؠ؅⹨ׄ⪌׿׾
    

    View full-size slide

  28. ⺎榫䓪כ䦡䍖䓪מחַי
    

    View full-size slide

  29. ⺎榫䓪
    ˝ جٜنك٭ٛ٤ء
    ˝ 3FQMJDBTFUֿؤ٤طػסوٞجت泃釱؅车
    ֹ
    ˝ زؘشؠמ㜊䷴׌׾כ.BOJGFTUך錃㲊׊ג
    ٝوٛ؜丗؅禴䧏׌׾׻ֹמ⥸ׂ
    ˝ /PEF꤃㲹侇מ׵1PE؅塜䅻ם/PEFמتآ
    ةٖ٭ٜ׊泡׌
    

    View full-size slide

  30. 䦡䍖䓪
    ˝ 姡䇖؛٭عتآ٭ٜ
    ˝ )PSJ[POUBM1PE"VUPTDBMFS )1"

    ˝ $16璡סْعٛؠت؅⹆拨׊י1PEסٝوٛ؜؅舅Ⳃך鴑ⱶ׌׾
    ˝ 㑈泡؛٭عتآ٭ٜ
    ˝ 7FSUJDBM1PE"VUPTDBMFS 71"

    ˝ $16 ْٓٛס✳榫ꄈ؅⮆冪׊יٛؠؙتع⡁؅䬠勅׊ג׽舅Ⳃ氳מ催
    二׊ג׽׌׾
    

    View full-size slide

  31. ـ٤ث؛٤ך⮵榫׌׾ص٭ٜ磆☭
    

    View full-size slide

  32. .JOJLVCF
    ˝ ٞ٭؜ٜ梪㗞ךLVCFSOFUFTסؠٚتذ٭؅玮ה┕ׅ׾סמ؛ت
    تْ
    IUUQTNJOJLVCFTJHTLTJPEPDTTUBSU
    ˝ LVCFSOFUFTסف٭ة٘٤؅䧗㲊׊יؠٚتذ٭؅啶疣ך׀׾
    ˝ ☽מ׵LJOEכַזגص٭ٜ׷%PDLFSGPS.BDמ♀㷯׊יַ׾
    LVCFSOFUFT׵ٞ٭؜ٜךؠٚتذ٭啶疣ֿ⺎耆
    

    View full-size slide

  33. ,VTUPNJ[F
    ˝ IUUQTHJUIVCDPNLVCFSOFUFTTJHTLVTUPNJ[F
    ˝ LTסُؼنؘتعס啶䡗؅؜تذُؕث׌׾ג״סص٭ٜ
    ˝ %FW 4UH 1SE璡ס邾丗ס梪㗞⮆.BOJGFTU؅傴ׂסע⫛Ꝏםס
    ךյ⪦鵟סي٭تכם׾ُؼنؘتع؅⛼׽חחյ梪㗞夵ס䄐
    ⮆؅قشزنٜؒؕכ׊י畘杼ך׀׾׻ֹמם׾
    ˝ kustomization.yamlמלסُؼنؘتع؅✳ֹ־յTFDSFU
    ׷DPOHס錃㲊םל؅鋗鳭׌׾
    

    View full-size slide

  34. 4LBPME
    ˝ IUUQTTLBPMEEFW
    ˝ نٜؒؕס㚺催؅吾湳׊יؤ٤طػْؕ٭ةסلٜغյ
    LT梪㗞׫⹚何׌׾ص٭ٜ
    ˝ skaffold.yamlמ㵚霄כם׾نٜؒؕյEPDLFSْؕ٭ةյ
    ُؼنؘتع؅鋗鳭׌׾
    

    View full-size slide

  35. ,VCFSOFUFTـ٤ث؛٤
    

    View full-size slide

  36. ؓةؘ٤ر
    ˝ 瑬┉鼧)BUFOB*OUFSO梪㗞ך鷛ׯֹ
    ˝ 瑬◅鼧鋗嫎㚺䬵ئ٭لتס鴑ⱶ
    ˝ 瑬└鼧-FUTUSZ؛٭عتآ٭ٜ؅錃㲊׊׻ֹ
    

    View full-size slide

  37. 瑬┉鼧
    )BUFOB*OUFSO梪㗞ך鷛ׯֹ
    

    View full-size slide

  38. ׆ס侇ꝴעـ٤ث؛٤ך׌
    ˝ ┉稇מ䣆؅Ⳃ־׊י䣆⩕ס,VCFOFUFT梪㗞؅鉴זיײױ׊׺ֹ
    ˝ IBUFOB)BUFOB*OUFSO-FDUVSF

    ⩕מ׊גَٛةعٛ┕ך⛼哅׊ױ׌ ⹆縒鐐갭َٛةعٛ

    ˝ 鋗鬼׈׿יַ׾ؤُ٤غעյَٛةعٜٛ٭عך㲔车׊יׂד׈ַ
    ˝ ױ׍עHJUסCSBODI؅⮉׽ױ׊׺ֹ
    % git switch -c k8s-handson
    

    View full-size slide

  39. ئ٭لتס啶䡗
    

    View full-size slide

  40. ُؼنؘتعס啶䡗
    k8s
    ├── account
    │ ├── app.yaml
    │ ├── config
    │ │ └── schema.sql
    │ ├── db.yaml
    │ ├── kustomization.yaml
    │ ├── secret
    │ │ └── ecdsa-private.pem
    │ └── test.yaml
    ├── blog
    │ ├── app.yaml
    │ ├── config
    │ │ └── schema.sql
    │ ├── db.yaml
    │ ├── kustomization.yaml
    │ ├── secret
    │ │ └── account-ecdsa-public.pem
    │ └── test.yaml
    ├── kustomization.yaml
    ├── namespace.yaml
    ├── renderer-go
    │ ├── app.yaml
    │ └── kustomization.yaml
    └── system
    └── sa.yaml
    ˝ k8sظؔٝؠعֿُٛؼنؘتع糋׀㕙
    ˝ BDDPVOUCMPHSFOEFSFSHPכُؕؠٞئ٭لتׇכ
    מظؔٝؠعٛ؅⮆ׄ׾
    ˝ kustomization.yamlֿLVTUPNJ[Fס錃㲊نٜؒؕ
    

    View full-size slide

  41. apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    resources:
    - app.yaml
    - db.yaml
    - test.yaml
    secretGenerator:
    - name: blog-app-secret
    files:
    - secret/account-ecdsa-public.pem
    configMapGenerator:
    - name: blog-app-env-vars
    literals:
    # (snip)
    - name: blog-db-schema-config
    files:
    - config/schema.sql
    

    View full-size slide

  42. 颯Ⳃ
    # Minikube Λىಈ
    % minikube start !"kubernetes-version v1.19.8 !"driver docker
    % eval $(minikube docker-env)
    # context Λઃఆ
    % kubectl config set-context hatena-intern-2021 !"cluster=minikube !"user=minikube !"namespace=hatena-intern-2021
    % kubectl config use-context hatena-intern-2021
    # skaffold Λىಈ
    % make up
    skaffold dev !"cleanup=false
    

    View full-size slide

  43. 澬鏀
    % minikube -n hatena-intern-2021 service blog
    ˝ services/blog/templates/index.html؅傴׀䬵ֻיյ
    㚺催ֿ⹚何׈׿׾׆כ؅澬鏀׊ױ׊׺ֹ
    梪㗞ס⯡ꢜ
    % skaffold delete
    

    View full-size slide

  44. LVCFDUM؅✳ֹ嶖⤓
    CBTI[TIךסؤُ٤غ遨㱭ס錃㲊
    # bash
    source <(kubectl completion bash)
    # zsh
    source <(kubectl completion zsh)
    ֽ׌׌״
    ؙؕٛؓتס錃㲊؅׊יֽׂ
    alias k=kubectl
    

    View full-size slide

  45. ئ٭لتֿ颯Ⳃ׊יַ׾׆כ؅澬鏀׌׾
    DPOUFYUס⮉׽僀ֻ
    % kubectl config use-context hatena-intern-2021
    

    View full-size slide

  46. 1PEֿ颯Ⳃ׌׾喋㯸؅釤׻ֹ
    ┉䈱梪㗞؅⯡ꢜ׊יյ颯Ⳃ׊泡׊ױ׊׺ֹ
    % skaffold delete
    % make up
    ⮯ס珷儕ך㲔车׊י1PEס敯䛜؅釤׾
    % kubectl get pods -w
    % kubectl describe pods
    1PEֿ颯Ⳃ׊ג׆כ؅澬鏀׊י
    % minikube -n hatena-intern-2021 service blog
    ؅㲔车յهٞء؅⛼䡗׊יײױ׊׺ֹ
    

    View full-size slide

  47. ظفشء
    # Podͷৄࡉ৘ใͷදࣔ
    % kubectl describe pod blog
    # ωʔϜεϖʔε্ʹ͋ΔϦιʔεͷ৘ใΛදࣔ
    % kubectl get all
    # ىಈ͍ͯ͠ΔPodͰγΣϧΛىಈ͢Δ
    % kubectl exec -it svc/account !" /bin/sh
    ˝ 颯Ⳃ׊יַ׾وٞجتע
    !
    ps
    ˝ CMPHئ٭لتמؓؠجت
    !
    wget -q -O - blog:8080
    ˝
    !
    nslookup blog
    

    View full-size slide

  48. ظ٭ذي٭تסظفشء
    䣆⩕מNZTRMDMJFOUֿםַ㕙⺬עت؞شو׊יׂד׈ַ
    # ϙʔτͷసૹ
    % kubectl port-forward svc/blog-db 13306:3306
    # ϗετ͔ΒMySQLʹ઀ଓͰ͖ΔΑ͏ʹͳΔ
    % mysql -u root -h 127.0.0.1 -P 13306
    

    View full-size slide

  49. NFUSJDTTFSWFSס㵵⪌
    ˝ IUUQTHJUIVCDPNLVCFSOFUFTTJHTNFUSJDTTFSWFS
    % minikube addons enable metrics-server
    

    View full-size slide

  50. OPEFյQPEסْعٛؠت؅⹦䐂
    ⹦䐂ך׀׾ױךמ侇ꝴֿ־־׾סך㵼׊䏨זי־׼㲔车׌׾
    % kubectl top nodes
    NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
    docker-desktop 469m 5% 1873Mi 32%
    % kubectl top pods
    NAME CPU(cores) MEMORY(bytes)
    account-86649c57b4-jq26g 2m 3Mi
    account-db-55579cb588-mmfv6 15m 345Mi
    account-test-59c689cdd4-q89rh 0m 1Mi
    blog-db-6f7f4c8797-rxtnz 15m 406Mi
    blog-test-86cff5d98c-ttp2z 0m 0Mi
    renderer-go-7d8d7fdf64-qhn95 5m 13Mi
    

    View full-size slide

  51. ,VCFSOFUFT%BTICPBSEס㵵⪌
    ˝ IUUQTHJUIVCDPNLVCFSOFUFTEBTICPBSE
    % minikube dashboard
    

    View full-size slide

  52. 瑬◅鼧
    鋗嫎㚺䬵ئ٭لتס鴑ⱶ
    

    View full-size slide

  53. 鋗嫎㚺䬵ئ٭لتSFOEFSFS
    ˝ services/renderer-tsמֵ׾㲔逷؅LT┕ךⳂ־׌
    ˝ ظنؚٜعךעservices/renderer-goֿⳂַיַ׾
    ˝ k8s/renderer-go؅⹆縒מյk8s/renderer-ts؅鴑ⱶ
    

    View full-size slide

  54. ُؼنؘتع
    ˝ 鴑ⱶ׌׾ُؼنؘتع
    ˝ k8s/renderer-ts/kustomization.yaml
    ˝ k8s/renderer-ts/app.yaml
    ˝ 稴꥗׌׾ُؼنؘتع
    ˝ skaffold.yaml
    ˝ k8s/kustomization.yaml
    ˝ k8s/blog/kustomization.yaml
    

    View full-size slide

  55. ُؼنؘتعס鴑ⱶ
    % cp -R k8s/renderer-go k8s/renderer-ts
    % perl -i -pe 's/renderer-go/renderer-ts/g' k8s/renderer-ts/*.yaml
    ˝ k8s/renderer-goظؔٝؠعٛ؅ؤم٭׊יk8s/
    renderer-ts؅⛼䡗
    ˝ ُؼنؘتع⫂סrenderer-go؅renderer-tsמ糋׀䬵ֻ
    

    View full-size slide

  56. ُؼنؘتعס稴꥗
    TLBPMEZBNM
    apiVersion: skaffold/v2beta5
    kind: Config
    metadata:
    name: hatena-intern-2021
    build:
    artifacts:
    # (snip)
    - image: hatena-intern-2021-renderer-go
    context: services/renderer-go
    - image: hatena-intern-2021-renderer-ts #
    !
    context: services/renderer-ts #
    !
    local:
    # (snip)
    ˝ services/renderer-tsסEPDLFSْؕ٭ةסلٜغכLTؠٚتذ׫ס⹚何ֿ׈׿׾׻ֹמ׌׾
    

    View full-size slide

  57. ُؼنؘتعס稴꥗
    LTLVTUPNJ[BUJPOZBNM
    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    namespace: hatena-intern-2021
    resources:
    - namespace.yaml
    - account
    - blog
    - renderer-go
    - renderer-ts #
    !
    

    View full-size slide

  58. ُؼنؘتعס稴꥗
    LTCMPHLVTUPNJ[BUJPOZBNM
    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    # (snip)
    configMapGenerator:
    - name: blog-app-env-vars
    literals:
    - MODE=development
    - DATABASE_DSN=root@(blog-db:3306)/intern_2021_blog?time_zone=UTC&parseTime=true&loc=UTC
    - ACCOUNT_ADDR=account:50051
    - RENDERER_ADDR=renderer-ts:50051 #
    !
    - name: blog-test-env-vars
    # (snip)
    ˝ CMPHئ٭لتס鋗嫎㚺䬵ئ٭لت׫ס⺸׀⩝؅SFOEFSFSHP־׼SFOEFSFSUTמ㚺
    ֻ׾
    

    View full-size slide

  59. 1PEֿ塜䅻מ颯Ⳃ׊םַ㕙⺬
    ˝ kubectl get pods؅㲔车׊י⺨1PEֿ塜׊ׂ颯Ⳃ׊יַ׾
    ־לֹ־澬鏀׌׾
    ˝ kubectl describe pod renderer-tsך鎋碷䗯㕔؅澬鏀
    ˝ ם׏塜䅻מ颯Ⳃ׊םַ־⸉㍔؅䫒؀ֹ
    

    View full-size slide

  60. ⸉㍔
    ˝ SFOEFSFSUTס1PEס敯䛜ֿOOMKilledך䍚⯆磙▼׈׿יַ׾
    ˝ SFOEFSFSHPך錃㲊׊יַ׾ْٓٛס⯆꡾עSFOEFSFSUTךע餉׽ם־זגג״յ1PE颯
    Ⳃ侇מْٓٛ┘餉ך䍚⯆磙▼׈׿יַג
    ˝ k8s/renderer-ts/app.yaml؅稴꥗׊յ$16ْٓٛ⯆꡾؅㚺催׌׾
    resources:
    requests:
    cpu: 100m
    memory: 20Mi
    limits:
    cpu: 200m
    memory: 40Mi
    

    View full-size slide

  61. 㲔꤀מSFOEFSFSUTֿⳂׂ׆כ؅澬鏀׌׾
    ˝ kubectl get pods׻׽׌׬יס1PEֿ塜䅻מ颯Ⳃ׊יַ׾׆
    כ؅澬鏀
    ˝ minikube -n hatena-intern-2021 service blog
    ؅㲔车׊יهٚؗا־׼ئؕ٤ؓشو؅车ֹ
    ˝ 鋗◄؅⛼䡗׊renderer-tsئ٭لتֿⳂׂ׆כ؅澬鏀
    

    View full-size slide

  62. 瑬└鼧
    -FUTUSZ؛٭عتآ٭ٜ؅
    錃㲊׊׻ֹ
    

    View full-size slide

  63. CMPHئ٭لت؅؛٭عتآ٭ٜ׈׎׾
    ˝ 㛻ꄈמ׷זיׂ׾ٛؠؙتعמ㵚׊יٝتَ٤تס䑴璻侇ꝴס
    ף׼ח׀ֿםַ׻ֹמ׌׾
    ˝ ⯆硜
    ˝ SFTPVSDFTMJNJUTע㚺催׊םַ׆כ
    ˝ 僃⮣מ錃㲊׌׾1PEסٝوٛ؜丗עסױױמ׌׾׆כ
    ˝ ؓوٛآ٭ب٘٤ס錃㲊ע㚺催׊םַ׆כ
    

    View full-size slide

  64. BC "QBDIF#FODI
    מ׻׾靷蕔طتع
    % kubectl exec deploy/blog-test !" ab -n 1000 -c 10 http:!#blog:8080/
    ˝ -n鴜⟓׌׾ٛؠؙتعס丗
    ˝ -c⺱侇מٛؠؙتع׌׾丗
    ˝ CMPHئ٭لتסطتع㲔车榫סؤ٤طػ־׼BC؅㲔车ך׀׾׻
    ֹמ׊יֵ׾
    

    View full-size slide

  65. ⹆縒؛٭عتآ٭ٜס錃㲊؅׊יַיַםַ1PEסٝوٛ؜丗ֿס敯䛜
    % ab -n 1000 -c 10 http:!"localhost:8080/
    (snip)
    Server Software:
    Server Hostname: localhost
    Server Port: 8080
    Document Path: /
    Document Length: 831 bytes
    Concurrency Level: 10
    Time taken for tests: 97.873 seconds
    Complete requests: 1000
    Failed requests: 42
    (Connect: 0, Receive: 0, Length: 42, Exceptions: 0)
    Total transferred: 1099784 bytes
    HTML transferred: 796098 bytes
    Requests per second: 10.22 [#/sec] (mean)
    Time per request: 978.730 [ms] (mean)
    Time per request: 97.873 [ms] (mean, across all concurrent requests)
    Transfer rate: 10.97 [Kbytes/sec] received
    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 0 0 0.1 0 1
    Processing: 1 975 605.9 897 3696
    Waiting: 0 910 579.2 798 3696
    Total: 1 975 605.9 898 3696
    Percentage of the requests served within a certain time (ms)
    50% 898
    66% 1099
    75% 1299
    80% 1399
    90% 1798
    95% 2098
    98% 2498
    99% 2798
    100% 3696 (longest request)
    ˝ 靷蕔طتعמ־־זג侇ꝴע
    T
    ˝ ٛؠؙتعֵג׽ס䇖㏯侇ꝴע
    NT
    

    View full-size slide

  66. )PSJ[POUBM1PE"VUPTDBMFS )1"

    ˝ $16✳榫曍מ׻זי1PEס丗؅㘃峎׈׎י姡䇖מ؛٭عتآ٭
    ٜ׌׾☼磝ײ
    ˝ ؛٭عتآ٭ٜסꝴꣴעظنؚٜعךע熮ׇכםסך嫰䙫׌
    ׾
    ˝ ⛰䈱־BCؤُ٤غ؅㲔车׌׾䑒釐ֵֿ׾־׵׊׿םַ
    

    View full-size slide

  67. ؛٭عتآ٭ٜס錃㲊
    % kubectl autoscale deployment blog !"cpu-percent=50 !"min=1 !"max=10
    ˝ !"cpu-percent泘嘅כם׾1PE⪒⛮ס䇖㏯$16✳榫曍
    ˝ !"min؛٭عتآ٭ٜ׌׾꤀ס1PE丗ס┖꡾
    ˝ !"max؛٭عتآ٭ٜ׌׾꤀ס1PE丗ס┕꡾
    

    View full-size slide

  68. 澬鏀׌׾׆כ
    ˝ BCס磵冽־׼⛰ֿ؂־׾־
    ˝ ٛؠؙتعֵג׽ס䇖㏯侇ꝴע
    ˝ ,VCFSOFUFT%BTICPBSE־׼⮆־׾׆כע
    ˝ CMPH1PEעַׂחױך㘃ֻג־
    ˝ kubectl get hpa blogך؛٭عتآ٭ٜס敯䛜؅澬鏀׊׻ֹ
    ˝ ┉㲊僿ꝴؓؠجت׎׍מ䷑糋׊יتآ٭ٜرؗ٤ס喋㯸׵釤יײ׾
    

    View full-size slide

  69. 撴טׄ
    % kubectl delete hpa blog
    

    View full-size slide

  70. ױכ״
    ˝ LVCFSOFUFTס哭鈝כ㓹儖氳ם嚀耆؅磆☭׊ג
    ˝ ؤ٤طػ؛٭آتعٝ٭ب٘٤׌׾ג״ס☼磝ײ؅⤓ֻגوٚشعنؚ٭ّ
    ˝ 㲚銧氳מؕ٤نٚ؅畘杼ך׀յ냕⺎榫ך䦡䍖䓪סֵ׾㓹泅؅啶疣ך׀׾
    ˝ قهٛشؠؠٚؗغך׵䬠❠׈׿יַ׾ؤ٤طػ؛٭آتعٝ٭ب٘٤סظنؒؠعتذ٤
    ر٭غ
    ˝ ـ٤ث؛٤؅鵟׊יLVCFSOFUFT؅⛮꽦׊ג
    ˝ LVCFSOFUFT梪㗞؅啶疣׊יئ٭لت؅Ⳃ־׌׆כע哧׊ַ
    ˝ .BOJGFTU־׼䣆鬭מتآ٭ٜ⺎耆ך䦡䍖䓪ס냕ַئ٭لت؅⛼׾׆כֿך׀׾
    ˝ 䣆鬭׈ס遊מע邾ꥭםؕ٤نٚ׷ؾشع٠٭ؠֿ㰆㏇׊יַ׾
    

    View full-size slide