Slide 1

Slide 1 text

1)1$POGFSFODF+BQBO3&CPSO 1)1PO,VCFSOFUFT

Slide 2

Slide 2 text

ొஃऀ঺հ ▸ Kouta Ozaki ▸ Chatwork, YAML Engineer

Slide 3

Slide 3 text

01 ·ͱΊ

Slide 4

Slide 4 text

·ͱΊ ,VCFSOFUFTͰ΋ී௨ʹ1)1ಈ͘ ಛʹ΄͔ʹ͍͏͜ͱ͕ͳ͍͙Β͍ී௨ʹಈ͘

Slide 5

Slide 5 text

ಇ͘Λ΋ͬͱָ͘͠ɺ૑଄తʹ

Slide 6

Slide 6 text

02 ,VCFSOFUFTʁ

Slide 7

Slide 7 text

w ෳ਺ͷαʔόʔʹɺෳ਺ͷίϯςφΛྑ͍ײ͡ʹ഑ஔͯ͘͠ΕΔͷ͕ίϯςφΦʔέετϨʔγϣϯ w ͦͷதͷσϑΝΫτελϯμʔτͳͷ͕,VCFSOFUFT w &,4ɺ(,&ɺ",&ͱ֤छΫϥ΢υͰ,VCFSOFUFTͷϚωʔδυαʔϏε΋ఏڙ͞Ε͍ͯΔ Kubernetes? ίϯςφΦʔέετϨʔγϣϯπʔϧͷσϑΝΫτελϯμʔυ

Slide 8

Slide 8 text

Kubernetes? 7.ͱ4FSWFSMFTTͱͷൺֱ ىಈ଎౓ ֶशίετ ੍໿ ߴ ௿ ௿ த ߴ த ௿ த ߴ 7. ,VCFSOFUFT 4FSWFSMFTT

Slide 9

Slide 9 text

03 1)1ΞϓϦέʔγϣϯͷίϯςφԽ

Slide 10

Slide 10 text

PHPΞϓϦέʔγϣϯͷίϯςφԽ ίϯςφͷߏஙํ๏ ɹFROM php:7.4-fpm ɹRUN docker-php-ext-install \ opcache \ pdo_mysql \ && pecl install \ redis \ xdebug \ && docker-php-ext-enable \ redis w %PDLFS)VCެࣜͰ1)1Πϝʔδ͕഑෍͞Ε͍ͯΔ w $-*"QBDIF'1.ͳͲ༻్ʹ߹Θͤͯ w &YUFOTJPO΍1&$-ͷ௥Ճ΋Մೳ w ઃఆϑΝΠϧ͸VTSMPDBMFUDҎԼʹ഑ஔ

Slide 11

Slide 11 text

PHPΞϓϦέʔγϣϯͷίϯςφԽ ઃఆͷ஫ೖํ๏ ؀ڥม਺ ઃఆϑΝΠϧ getenv('APP_PARAM1') ?: 'ABC', 'param2' => getenv('APP_PARAM2') ?: 'DEF', ]; 'ABC', 'param2' => 'DEF', ]; w ίϯςφىಈ࣌ʹ؀ڥม਺Λࢦఆ͢Δ͚ͩ w ؀ڥม਺͕ͳ͚Ε͹ॳظ஋Ͱ͸ͳ͘EJF͢ΔͱΑΓ ҆શ w ؀ڥม਺͕਺ඦʹͳΔͱΘ͚Θ͔Μͳ͘ͳΔ w ίϯςφىಈ࣌ʹϑΝΠϧΛϚ΢ϯτɺ΋͘͠͸ ؀ڥม਺ͰಡΈࠐΉϑΝΠϧΛ੾Γସ͑ w ϑΝΠϧ੾Γସ͑ͷ৔߹ɺઃఆΛม͑Δ౓ʹίϯ ςφͷϏϧυ͕ඞཁ w ઃఆϑΝΠϧͷਖ਼͠͞ΛͲ͏ݕূ͢Δ͔͕伴

Slide 12

Slide 12 text

PHPΞϓϦέʔγϣϯͷίϯςφԽ ϩάͷग़ྗํ๏ pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); $logger->info("output log"); w ίϯςφϩάʹ͸ίϯςφͷϝΠϯϓϩηεͷ45%065ͱ45%&33͕ग़ྗ͞ΕΔ w ͦͷͨΊɺΞϓϦέʔγϣϯϩά͸45%06545%&33ʹग़ྗ͢Ε͹0, w 45%065ͱ45%&33͸࢖͍෼͚ͯ΋͍͍͚Ͳɺίϯςφϩάͷऩूج൫ʢ'MVFOUEͳͲʣͳͲͰৼ Γ෼͚΋͓͜ͳ͑ΔͷͰͦ͜·Ͱͩ͜ΘΒͳͯ͘΋Α͍

Slide 13

Slide 13 text

PHPΞϓϦέʔγϣϯͷίϯςφԽ ϩάͷग़ྗํ๏ error_log = /dev/stderr log_errors = On log_errors_max_len = 16384 w 1)1ͷ'BUBMFSSPSͳͲ͸QIQJOJͷFSSPS@MPHͰग़ྗ w ͜ͷͱ͖ϩά͸ෳ਺ߦͰग़ྗ͞ΕΔͨΊͲ͔͜ͰϩάΛ݁߹͠ͳ͚Ε͹͍͚ͳ͍͜ͱʹ஫ҙ w ϩάͷ௕͞͸QIQJOJͷMPH@FSSPST@NBY@MFOͱQIQGQNDPOGͷMPH@MJNJUͰࢦఆ w ͜ΕΑΓ୹͍৔߹͸ϩά͕੾Γ٧ΊΒΕΔ w 1)1'1.ͰϩάΛग़͢ͱෆཁͳ઀಄͕ࣙೖΔͷͰEFDPSBUF@XPSLFST@PVUQVUͰΦϑʹ w Φϯͩͱ8"3/*/(DIJMETBJEJOUPTUEFSSYYYͱ͍͏Α͏ʹແବʹ௕͍ log_limit = 16384 catch_workers_output = yes decorate_workers_output = no QIQJOJ QIQGQNDPOG

Slide 14

Slide 14 text

04 1)1ΞϓϦέʔγϣϯͷ,VCFSOFUFTԽ

Slide 15

Slide 15 text

w ,VCFSOFUFTͷ࠷খ୯Ґ͸1PE w 1PEͷதʹͭҎ্ͷίϯςφ͕ೖΔ w 1PEͷઃܭ͸1)1Ͱ͸બ୒ࢶ͕͍͔ͭ͋͘Δ w "QBDIF w /(*/91)1'1. w Ұͭͷίϯςφʹ·ͱΊΔ w ෳ਺ͷίϯςφʹΘ͚Δ w /(*/9*OHSFTT 1)1ʹ͸1PEͷߏ੒ύλʔϯ͕͍͔ͭ͋͘Δ PHPΞϓϦέʔγϣϯͷKubernetesԽ

Slide 16

Slide 16 text

w "QBDIF1)1͸୯ҰίϯςφͰಈ͔ͤΔ w ಛʹཧ༝͕ͳ͚Ε͹൪ָ PHPΞϓϦέʔγϣϯͷKubernetesԽ "QBDIFΛར༻ͨ͠ύλʔϯ

Slide 17

Slide 17 text

w /(*/9'1.ΛҰͭͷίϯςφͰಈ͔ͤΔ w %PDLFSϕετϓϥΫςΟεʹҧ൓͍ͯ͠Δ w ίϯςφΞϓϦέʔγϣϯ w /(*/9ͱ'1.Λ؅ཧ͢Δ4VQFSWJTPSͱ͔ඞཁ PHPΞϓϦέʔγϣϯͷKubernetesԽ /(*/9ʴ'1.ͰಉҰίϯςφʹͨ͠ύλʔϯ

Slide 18

Slide 18 text

w 1PE಺ͷίϯςφΛ/(*/9ͱ'1.ͰΘ͚ΒΕΔ w ιʔείʔυΛͲ͏΍ͬͯಉظ͢Δ͔ w ͦΕͧΕͷίϯςφʹόϯυϧ w JOJU$POUBJOFSͰιʔείʔυΛίϐʔ PHPΞϓϦέʔγϣϯͷKubernetesԽ /(*/9ʴ'1.Ͱผίϯςφʹͨ͠ύλʔϯ

Slide 19

Slide 19 text

PHPΞϓϦέʔγϣϯͷKubernetesԽ /(*/9ʴ'1.Λผ1PEʹͨ͠ύλʔϯ w 1PEࣗମΛ/(*/9ͱ'1.ͰΘ͚ΒΕΔ w εέʔϧ΍σϓϩΠλΠϛϯάΛͣΒͤΔ w ιʔείʔυͷಉظํ๏͕ίϯςφʹόϯυϧͯ͠σϓϩΠλΠϛϯάΛἧ͑Δ͔͠ͳ͍

Slide 20

Slide 20 text

PHPΞϓϦέʔγϣϯͷKubernetesԽ /(*/9*OHSFTT1)1'1.Λར༻ͨ͠ύλʔϯ w /(*/9*OHSFTT͕'BTU$(*ʹରԠ͍ͯ͠Δ w IUUQTHJUIVCDPNLVCFSOFUFTJOHSFTTOHJOY w ͪ͜Β΋ιʔείʔυͷಉظ͸՝୊ w /(*/9*OHSFTTͷੜ੒͢Δ/(*/9ͷઃఆେ͖͍ w ϓϩμΫγϣϯͰͦͷઃఆΛอक͖͠ΕΔ͔ w ύλʔϯͷํ͕γϯϓϧ

Slide 21

Slide 21 text

PHPΞϓϦέʔγϣϯͷKubernetesԽ ͍͔ͭ͘ͷύλʔϯʹରԠͨ͠1)1$IBSU IUUQTHJUIVCDPNDIBUXPSLDIBSUTUSFFNBTUFSQIQ

Slide 22

Slide 22 text

PHPΞϓϦέʔγϣϯͷKubernetesԽ 1PEͷऴྃॲཧ ɹlifecycle: ɹɹpreStop: exec: command: - /bin/sh - -c - sleep 60; kill -QUIT 1; sleep 60 1PE 3VOOJOH 5FSNJOBUJOH 4FSWJDF 1SF4UPQ %FUBDI4FSWJDF 4*(5&3. 4*(,*-- UFSNJOBUJPO(SBDF1FSJPE4FDPOET EFGBMUT pOJTIQSFTUPQ UFSNJOBUFQPE w ίϯςφͷऴྃॲཧ͸4*(5&3.ͳͷͰQSF4UPQதʹ 4*(26*5Λૹͬͯ(SBDFq4IVUEPXO͢Δ w LJMM͸ඇಉظͳͷͰϦΫΤετͷॲཧ࣌ؒ଴ͭ w ऴྃॲཧதʹ4FSWJDF͔Β৽نϦΫΤετ͕ϧʔςΟϯ ά͞Εͳ͍Α͏ʹগ͠଴ͭඞ༻͕͋Δ

Slide 23

Slide 23 text

w ,VCFSOFUFTͷϝτϦΫεऩूج൫ͷ1SPNFUIFVT΋ར༻Մೳ w "QBDIF&YQPSUFSɺ/(*/9&YQPSUFSɺ1)1'1.&YQPSUFSΛར༻͢Δ͜ͱͰϝτϦΫεΛऩू w 1)1Ͱ&YQPSUFSΛ࡞ΔͨΊͷϥΠϒϥϦ΋͋Δ w FOEDMPUIJOHQSPNFUIFVT@DMJFOU@QIQ w 01$BDIF΍"1$VͷϝτϦΫεͷऩूͱ͔Ͱར༻ PHPΞϓϦέʔγϣϯͷKubernetesԽ &YQPSUFSΛ࢖ͬͨϝτϦΫεͷऩू

Slide 24

Slide 24 text

05 ,VCFSOFUFTΛ։ൃ؀ڥͱͯ͠࢖͑Δ͔

Slide 25

Slide 25 text

KubernetesΛ։ൃ؀ڥͱͯ͠࢖͑Δ͔ 1IQ4UPSNͱ9EFCVHPO,VCFSOFUFT w 9EFCVH͔Β1IQ4UPSNʹͭͳ͕Ε͹0, w %PDLFSGPS.BDͷ৔߹͸EPDLFSGPSNBDMPDBMIPTUͰϗετʹͭͳ͕Δ w ϦϞʔτͷ,VCFSOFUFTΫϥελͷ৔߹͸1PE͔Β௨৴Մೳͳঢ়ଶʹ͢Δ w 9EFCVHͷೖͬͨ1PE͔Βϗετ΁ૄ௨Մೳʹ͢Ε͹0,

Slide 26

Slide 26 text

w 1IQ4UPSN͸,VCFSOFUFTʹରԠ͍ͯ͠ͳ͍ w ΋͠ରԠ͢ΔͳΒEPDLFSFYFDΛϥοϓͨ͠QIQίϚϯυΛ༻ҙ͢ΔʢLVCFDUMͰ΋Մʣ w ͜ͷϑΝΠϧ΁ͷύεΛ1IQ4UPSNͷ$-**OUFSQSFUFSʹࢦఆ͢Δͱಈ࡞͢Δ w ͨͩ͠ɺύεͷϚοϐϯά͸ޮ͔ͳ͍ͷͰϩʔΧϧͱ,VCFSOFUFTͰಉҰͷύεʹ͢Δඞ༻͕͋Δ w Ϛ΢ϯτ͢ΔύεΛௐ੔͢ΔͳΓɺMJGFDZDMFQSF4UBSUͰTZNMJOLΛషΔͳΓ w ࡞੒ͨ͠ίϚϯυͰύεΛஔ͖׵͑ͯ΋ྑ͍͔΋ʁ KubernetesΛ։ൃ؀ڥͱͯ͠࢖͑Δ͔ 1IQ4UPSNͱ1)16OJUPO,VCFSOFUFT ɹ#!/bin/sh ɹCONTAINER_ID=$(docker ps -f name=php-fpm -q --latest) ɹdocker exec $CONTAINER_ID php "$@"

Slide 27

Slide 27 text

KubernetesΛ։ൃ؀ڥͱͯ͠࢖͑Δ͔ ଞ؀ڥͱͷൺֱ 6OJU5FTU $PNQPTFS ॳճىಈ NT NT NT NT N NT NT N NT 7BHSBOU ,VCFSOFUFT EPDLFSDPNQPTF ճ໨ͷىಈ N N N

Slide 28

Slide 28 text

06 ·ͱΊ

Slide 29

Slide 29 text

·ͱΊ ,VCFSOFUFTͰ΋ී௨ʹ1)1ಈ͘ ಛʹ΄͔ʹ͍͏͜ͱ͕ͳ͍͙Β͍ී௨ʹಈ͘ ֶͨͩ͠शίετ͸ߴ͍

Slide 30

Slide 30 text

ಇ͘Λ΋ͬͱָ͘͠ɺ૑଄తʹ