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

PHP on Kubernetes - PHP Conference 2020 Re:born...

Kouta Ozaki
December 12, 2020

PHP on Kubernetes - PHP Conference 2020 Re:born #phpcon

Kouta Ozaki

December 12, 2020
Tweet

More Decks by Kouta Ozaki

Other Decks in Programming

Transcript

  1. 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ҎԼʹ഑ஔ
  2. PHPΞϓϦέʔγϣϯͷίϯςφԽ ઃఆͷ஫ೖํ๏ ؀ڥม਺ ઃఆϑΝΠϧ <?php return [ 'param1' => getenv('APP_PARAM1')

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

    Logger('containerlog'); $logger->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ͳͲʣͳͲͰৼ Γ෼͚΋͓͜ͳ͑ΔͷͰͦ͜·Ͱͩ͜ΘΒͳͯ͘΋Α͍
  4. 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/*/(<QPPMXXX>DIJMETBJEJOUPTUEFSSYYYͱ͍͏Α͏ʹແବʹ௕͍ log_limit = 16384 catch_workers_output = yes decorate_workers_output = no QIQJOJ QIQGQNDPOG
  5. 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Խ
  6. 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͔Β৽نϦΫΤετ͕ϧʔςΟϯ ά͞Εͳ͍Α͏ʹগ͠଴ͭඞ༻͕͋Δ
  7. KubernetesΛ։ൃ؀ڥͱͯ͠࢖͑Δ͔ ଞ؀ڥͱͷൺֱ 6OJU5FTU $PNQPTFS ॳճىಈ NT NT NT NT N

    NT NT N NT 7BHSBOU ,VCFSOFUFT EPDLFSDPNQPTF ճ໨ͷىಈ N N N