Skaffoldを使ってKubernetes してみた/skaffold_k8s

Skaffoldを使ってKubernetes してみた/skaffold_k8s

PHPカンファレンス福岡2018での発表に用いた資料です。

83f9862ef4599c97e99d020eb8e20d87?s=128

KOYAMA Tetsuji

June 16, 2018
Tweet

Transcript

  1. PHPΧϯϑΝϨϯε෱Ԭ2018 2018-06-16 4LB⒎PMEΛ࢖ͬͯ ,VCFSOFUFTͯ͠Έͨ খࢁ఩ࢤ !LPZIPHF

  2. ࣗݾ঺հ খࢁ఩ࢤ ͜΍·ͯͭ͡  ߹ಉձࣾ΄ٕ͛ݚ Ϣʔβձ͍͔ͭ͘ ೔ຊ6/*9Ϣʔβձ ೔ຊ1PTUHSF42-Ϣʔβձ ೔ຊ1)1Ϣʔβձ SBLVNPגࣜձࣾΤϯδχΞ

    !LPZIPHF LPZIPHF
  3. w (4VJUF (NBJM (PPHMFΧϨϯμʔͳͲ ʹػೳ௥Ճ͠ ͯൢച w ಋೖ ࣾҎ্ w

    IUUQTSBLVNPDPN w ࡢ೥(PPHMF$MPVE1MBUGPSN ($1 ͷύʔτφʔʹ
  4. ࠓճͷ಺༰ w ,VCFSOFUFTͷྺ࢙ w ,VCFSOFUFTͷಛ௃ w 4LB⒎PMEͷಛ௃ w 4LB⒎PMEͷ࢖͍ํ

  5. ,VCFSOFUFT w IUUQTLVCFSOFUFTJP w LTͱུ͞ΕΔ w ಡΈ͸ʮ͘ʔ͹Ͷͯ͌͢ʯ w %PDLFS޲͚ΦʔέετϨʔγϣϯπʔϧ

  6. ࠓճͷ಺༰ w ,VCFSOFUFTͷྺ࢙ w ,VCFSOFUFTͷಛ௃ w 4LB⒎PMEͷಛ௃ w 4LB⒎PMEͷ࢖͍ํ

  7. LTIJTUPSZ w ೥(PPHMFͷࣾ಺πʔϧͱͯ͠։ൃ։࢝ w (PPHMFͷ#PSH͔Βڧ͍ӨڹΛड͚ͨ1SPKFDU4FWFO w 4FWFO͸4UBS5SFL7PZBHFSͷ4FWFOPG/JOF͔Β w ϩΰͷຊεϙʔΫͷ଩ͷ༝དྷ w

    ʹWϦϦʔε w ͦͷޙ$/$'ʹҠ؅ #Z4PVSDF 81/'$$ 'BJSVTF  IUUQTFOXJLJQFEJBPSHXJOEFYQIQ DVSJE
  8. LT%PDLFS w %PDLFS$PO&6 w LTͷ%PDLFSͱ౷߹Λൃද w ࣄ্࣮ͷඪ४ΦʔέετϨʔγϣϯπʔϧʹ w ͦͷޙΫϥ΢υք۾͕૽͕͘͠ͳΔ

  9. w (PPHMF$POUBJOFS&OHJOF w ($1ͷ%PDLFSίϯςφӡ༻ϚωʔδυαʔϏε w ུশ͸(,& ($&͸$PNQVUF&OHJOFʹ࢖ΘΕ͍ͯ ͨ  w

    (PPHMF,VCFSOFUFT&OHJOF (,& ʹվ໊ LTPO($1
  10. w "[VSF$POUBJOFS4FSWJDF "$4  w ࠷ॳ͸"QBDIF.FTPTϕʔε w ෳ਺ͷΦʔέετϨʔγϣϯπʔϧΛαϙʔτ w "[VSF$POUBJOFS4FSWJDF

    ",4  w ,VCFSOFUFTϕʔε w "[VSF,VCFSOFUFT4FSWJDF ",4 ʹվ໊ LTPO"[VSF
  11. w &MBTUJD$POUBJOFS4FSWJDFGPS,VSCFSOFUFT &,4   w &$4ͱ͍͏ಠࣗϚωʔδυαʔϏεΛ͢Ͱʹ΋͍ͬͯ ͨ w LTඪ४ͷྲྀΕΛड͚ͯαʔϏε௥Ճ

    LTPO"84
  12. ࠓճͷ಺༰ w ,VCFSOFUFTͷྺ࢙ w ,VCFSOFUFTͷಛ௃ w 4LB⒎PMEͷಛ௃ w 4LB⒎PMEͷ࢖͍ํ

  13. w ʮγεςϜΛߏ੒͢ΔϓϥοτϑΥʔϜ΍ϛυϧ΢ΣΞɺ αʔϏεɺΞϓϦέʔγϣϯɺ؅ཧπʔϧͳͲͷઃఆ΍؅ ཧΛࣗ཯తʹ࿈ܞͤ͞Δ͜ͱɻʯ
 ;%/FU+BQBOΩʔϫʔυղઆΑΓ w ΦʔέετϨʔγϣϯͱ͸ͳʹ͔

  14. w ༷ʑͳ໾ׂͷίϯςφΛ૊Έ߹ΘͤͯαʔϏεΛ࡞Δͱ ͖ͷɺӡ༻ͷෳࡶੑΛղܾ͢Δ w (PPHMF͕#PSHΛӡ༻͖ͯͨ͠ͱ͖ͷ஌ݟ͕٧·ͬͯ ͍Δ LT͸ԿΛղܾ͢Δͷ͔

  15. w Πϛϡʔλϒϧ w એݴతઃఆ w ΦϯϥΠϯͰࣗݾճ෮͢Δ LTͷઃܭίϯηϓτ

  16. w *NNVUBCJMJUZ w Ұ౓࡞੒ͨ͠Βมߋ͞Εͳ͍ w ඞཁʹԠͯ͡ಉ͡಺༰ͷίϯςφΛ͍ͭ͘΋ىಈͰ͖Δ Πϛϡʔλϒϧ

  17. w ʮԿΛ͢Δ͔ʯͰ͸ͳ͘ʮͲ͏͋Δ΂͖͔ʯΛهड़͢Δ w ࠷ऴతͳ๬·͍͠ঢ়ଶΛॻ͘ એݴతઃఆ

  18. w ๬·͍͠ঢ়ଶ͸஌͍ͬͯΔ w ܧଓతʹ؂ࢹ͠ɺ๬·͍͠ঢ়ଶʹͳ͍ͬͯͳ͔ͬͨΒͦΕ ʹҰக͢ΔΑ͏ʹಈ͖ଓ͚Δ ࣗݾճ෮͢Δ

  19. apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: -

    name: nginx image: nginx:1.7.9 ports: - containerPort: 80 nginx-pod.yml
  20. w Ϋϥελ w 1PE w 4FSWJDF w 3FQMJDB4FU w %BFNPO4FU

    w +PC w %FQMPZNFOU w $POpH.BQ LTߏ੒ཁૉ
  21. w Ϋϥελ w 1PE w 4FSWJDF w 3FQMJDB4FU w %BFNPO4FU

    w +PC w %FQMPZNFOU w $POpH.BQ LTߏ੒ཁૉ
  22. w LT؀ڥΛߏ੒͢ΔϚγϯ܈ w %PDLFS͕ಈ͚͹෺ཧ࿦ཧͲͪΒͰ΋ྑ͍ w Ϋϥ΢υαʔϏεͰ͸؅ཧը໘ͰϙνΔ͚ͩ Ϋϥελ

  23. w ϫʔΫϩʔυ ίϯςφ ͕ಈ࡞͢Δ࿦ཧϊʔυ w ෳ਺ͷϫʔΫϩʔυ͕ಈ࡞͢Δ৔߹΋͋Δ w ಉҰ1PEͷ৔߹͸ɺϑΝΠϧγεςϜͰίϯςφಉ࢜ ͕΍ΓऔΓ͢Δ͜ͱ΋Մೳ 1PE

  24. w ໊લղܾ w ಺෦Ͱ%/4͕ಈ͍͍ͯΔ w ֎෦΁ͷΤϯυϙΠϯτ࡞੒ 4FSWJDF

  25. w αʔϏεҰࣜΛ഑ஔ͢Δ࢓૊Έ w ࢮ׆؂ࢹ w ߏ੒มߋɾΦʔτεέʔϧ w %PDLFSΠϝʔδͷߋ৽ w Ξοϓσʔτઓུ

    %FQMPZNFOU
  26. w LT؅ཧίϚϯυ w جຊ͸͜ͷίϚϯυ͔Β͢΂ͯΛߦ͏ LVCFDUM

  27. w IPHFZNMʹαʔϏεͷ͢΂ͯΛॻ͘ํࣜ w ͍ͨ΁Μγϯϓϧ w :".-Ͱ͔͗͢໰୊ σϓϩΠ $ kubectl apply

    -f hoge.yml
  28. ࠓճͷ಺༰ w ,VCFSOFUFTͷྺ࢙ w ,VCFSOFUFTͷಛ௃ w 4LB⒎PMEͷಛ௃ w 4LB⒎PMEͷ࢖͍ํ

  29. w IUUQTHJUIVCDPN(PPHMF$POUBJOFS5PPMT TLB⒎PME w ϫʔΫϑϩʔͷࣗಈԽπʔϧ w ·ͩΞϧϑΝ൛Ͱ࣮ݧతͳҐஔ͚ͮ w ࠷৽൛͸ʹϦϦʔε͞Εͨ 4LB⒎PME

  30. w .BUU3JDLBSE͞Μ w IUUQTHJUIVCDPNSE w ($1ΤϯδχΞ w NJOJLVCFʹ΋ؔΘ͍ͬͯΔ ࡞ͬͨͷ͸͜ͷਓ

  31. w ίϯςφϕʔε։ൃͷ$* w %PDLFSΠϝʔδͷ࡞੒ɺϨδετϦ΁ͷొ࿥ɺσϓϩΠ ͷͦΕͧΕΛࣗಈԽ ԿΛղܾ͢Δ΋ͷ

  32. None
  33. w ։ൃ࣌ w ϏϧυϩʔΧϧͷEPDLFSCVJME w ొ࿥ͳ͠ w σϓϩΠNJOJLVCFʹLVCFDUM w ຊ൪࣌

    ($1ͷ৔߹  w Ϗϧυ(PPHMF$POUBJOFS#VJMEFSʹ౤͛Δ w ొ࿥(PPHMF$POUBJOFS3FHJTUSZʹొ࿥͢Δ w σϓϩΠ(,&ʹLVCFDUM ྆ऀͷҧ͍
  34. w ΠϝʔδSFQPͷλάΛࣗಈͰଧͬͯ͘ΕΔɻ w ։ൃ࣌͸ϑΝΠϧΛ؂ࢹͯ͠ɺมߋ͕͋ͬͨΒࣗಈͰσϓ ϩΠ·Ͱ΍ͬͯ͘ΕΔ ·ͩ͋Δศརػೳ

  35. w #B[FM w IUUQTCB[FMCVJME w )FMN w IUUQTIFMNTI w LBOJLP

    w IUUQTHJUIVCDPN(PPHMF$POUBJOFS5PPMTLBOJLP w LVTUPNJ[F w IUUQTHJUIVCDPNLVCFSOFUFTTJHTLVTUPNJ[F w ෳ਺ΠϝʔδͷରԠ NJDSPTFSWJDF ֤छπʔϧରԠ
  36. ࠓճͷ಺༰ w ,VCFSOFUFTͷྺ࢙ w ,VCFSOFUFTͷಛ௃ w 4LB⒎PMEͷಛ௃ w 4LB⒎PMEͷ࢖͍ํ

  37. w TLB⒎PMEίϚϯυͷΠϯετʔϧ w ඞཁͳΒ LVCFDUM NJOJLVCFͷΠϯετʔϧ w ຊ൪σϓϩΠ؀ڥͷ༻ҙ ྫ(,& Ͱ͸࢖ͬͯΈΑ͏

  38. w TLB⒎PME͸HP੡ w ֤ϓϥοτϑΥʔϜ༻όΠφϦΛ഑͍ͬͯΔͷͰࣗ෼Ͱ Ϗϧυ͢Δඞཁ͸ͳ͍ w .BDͳΒ TLB⒎PMEίϚϯυ curl -Lo

    skaffold https://storage.googleapis.com/skaffold/ releases/latest/skaffold-darwin-amd64 && chmod +x skaffold && sudo mv skaffold /usr/local/bin
  39. w NBJOHPΛίϯύΠϧ࣮ߦ͢Δ͚ͩͷαϯϓϧ FYBNQMFTHFUUJOHTUBSUFE

  40. NBJOHP package main import ( "fmt" "time" ) func main()

    { for { fmt.Println("Hello world!") time.Sleep(time.Second * 1) } }
  41. %PDLFSpMF FROM golang:1.10.1-alpine3.7 as builder COPY main.go . RUN go

    build -o /app main.go FROM alpine:3.7 CMD ["./app"] COPY --from=builder /app .
  42. TLB⒎PMEZNM apiVersion: skaffold/v1alpha2 kind: Config build: artifacts: - imageName: gcr.io/myproj-koyhoge/skaffold-gcb

    deploy: kubectl: manifests: - k8s-* profiles: - name: gcb build: googleCloudBuild: projectId: myproj-koyhoge
  43. LTQPEZNM apiVersion: v1 kind: Pod metadata: name: getting-started spec: containers:

    - name: getting-started image: gcr.io/myproj-koyhoge/skaffold-gcb
  44. TLB⒎PMEEFW Ϗϧυ ొ࿥ σϓϩΠ

  45. w ϑΝΠϧอଘͱಉ࣌ʹҰ࿈ͷ࡞ۀ͕࠶ͼߦΘΕΔ ͦͷ··ϑΝΠϧมߋ fmt.Println("Hello world!") Λ fmt.Println("Hello phpconfuk!") ΁

  46. w Ҏ্ɺऴྃ ຊ൪σϓϩΠ $ skaffold run

  47. w ඪ४తͳ$*$%ͱόοςΟϯά͠ͳ͍  w ͱ΋͋Ε͢΂ͯΛίϯςφͰ·͔ͳ͏ࢼΈ͸໘ന͍ w ͜͜ͰഓΘΕ͍ͯΔ஌ݟ͸ɺผͷ$*$%ͷ࢓૊ΈͰ΋׆ ͔ͤΔͩΖ͏ ࢼͯ͠ͷײ૝

  48. w LT͸ࠓͱͯ΋Ξπ͍ w TLB⒎PMEΛ͸͡Ίɺ͞·͟·ͳपลπʔϧ͕։ൃ͞Εɺ ৽͍͠ࢼΈ͕ߦΘΕ͍ͯΔ w αʔϏεͷ044ج൫ͱͯ͠ͷඪ४ʹͳΓͭͭ͋Δ ·ͱΊ