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

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

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

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

KOYAMA Tetsuji

June 16, 2018
Tweet

More Decks by KOYAMA Tetsuji

Other Decks in Programming

Transcript

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

    View full-size slide

  2. ࣗݾ঺հ
    খࢁ఩ࢤ ͜΍·ͯͭ͡

    ߹ಉձࣾ΄ٕ͛ݚ
    Ϣʔβձ͍͔ͭ͘
    ೔ຊ6/*9Ϣʔβձ
    ೔ຊ1PTUHSF42-Ϣʔβձ
    ೔ຊ1)1Ϣʔβձ
    SBLVNPגࣜձࣾΤϯδχΞ
    !LPZIPHF LPZIPHF

    View full-size slide

  3. w (4VJUF (NBJM (PPHMFΧϨϯμʔͳͲ
    ʹػೳ௥Ճ͠
    ͯൢച
    w ಋೖ ࣾҎ্
    w IUUQTSBLVNPDPN
    w ࡢ೥(PPHMF$MPVE1MBUGPSN ($1
    ͷύʔτφʔʹ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. LTIJTUPSZ
    w ೥(PPHMFͷࣾ಺πʔϧͱͯ͠։ൃ։࢝
    w (PPHMFͷ#PSH͔Βڧ͍ӨڹΛड͚ͨ1SPKFDU4FWFO
    w 4FWFO͸4UBS5SFL7PZBHFSͷ4FWFOPG/JOF͔Β
    w ϩΰͷຊεϙʔΫͷ଩ͷ༝དྷ
    w ʹWϦϦʔε
    w ͦͷޙ$/$'ʹҠ؅
    #Z4PVSDF 81/'$$
    'BJSVTF
    IUUQTFOXJLJQFEJBPSHXJOEFYQIQ DVSJE

    View full-size slide

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

    View full-size slide

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

    w (PPHMF,VCFSOFUFT&OHJOF (,&

    ʹվ໊
    LTPO($1

    View full-size slide

  10. w "[VSF$POUBJOFS4FSWJDF "$4

    w ࠷ॳ͸"QBDIF.FTPTϕʔε
    w ෳ਺ͷΦʔέετϨʔγϣϯπʔϧΛαϙʔτ
    w "[VSF$POUBJOFS4FSWJDF ",4

    w ,VCFSOFUFTϕʔε
    w "[VSF,VCFSOFUFT4FSWJDF ",4
    ʹվ໊
    LTPO"[VSF

    View full-size slide

  11. w &MBTUJD$POUBJOFS4FSWJDFGPS,VSCFSOFUFT &,4


    w &$4ͱ͍͏ಠࣗϚωʔδυαʔϏεΛ͢Ͱʹ΋͍ͬͯ
    ͨ
    w LTඪ४ͷྲྀΕΛड͚ͯαʔϏε௥Ճ
    LTPO"84

    View full-size slide

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

    View full-size slide

  13. w ʮγεςϜΛߏ੒͢ΔϓϥοτϑΥʔϜ΍ϛυϧ΢ΣΞɺ
    αʔϏεɺΞϓϦέʔγϣϯɺ؅ཧπʔϧͳͲͷઃఆ΍؅
    ཧΛࣗ཯తʹ࿈ܞͤ͞Δ͜ͱɻʯ

    ;%/FU+BQBOΩʔϫʔυղઆΑΓ
    w
    ΦʔέετϨʔγϣϯͱ͸ͳʹ͔

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. apiVersion: v1
    kind: Pod
    metadata:
    name: nginx
    spec:
    containers:
    - name: nginx
    image: nginx:1.7.9
    ports:
    - containerPort: 80
    nginx-pod.yml

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  32. w ։ൃ࣌
    w ϏϧυϩʔΧϧͷEPDLFSCVJME
    w ొ࿥ͳ͠
    w σϓϩΠNJOJLVCFʹLVCFDUM
    w ຊ൪࣌ ($1ͷ৔߹

    w Ϗϧυ(PPHMF$POUBJOFS#VJMEFSʹ౤͛Δ
    w ొ࿥(PPHMF$POUBJOFS3FHJTUSZʹొ࿥͢Δ
    w σϓϩΠ(,&ʹLVCFDUM
    ྆ऀͷҧ͍

    View full-size slide

  33. w ΠϝʔδSFQPͷλάΛࣗಈͰଧͬͯ͘ΕΔɻ
    w ։ൃ࣌͸ϑΝΠϧΛ؂ࢹͯ͠ɺมߋ͕͋ͬͨΒࣗಈͰσϓ
    ϩΠ·Ͱ΍ͬͯ͘ΕΔ
    ·ͩ͋Δศརػೳ

    View full-size slide

  34. w #B[FM
    w IUUQTCB[FMCVJME
    w )FMN
    w IUUQTIFMNTI
    w LBOJLP
    w IUUQTHJUIVCDPN(PPHMF$POUBJOFS5PPMTLBOJLP
    w LVTUPNJ[F
    w IUUQTHJUIVCDPNLVCFSOFUFTTJHTLVTUPNJ[F
    w ෳ਺ΠϝʔδͷରԠ NJDSPTFSWJDF

    ֤छπʔϧରԠ

    View full-size slide

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

    View full-size slide

  36. w TLB⒎PMEίϚϯυͷΠϯετʔϧ
    w ඞཁͳΒ
    LVCFDUM NJOJLVCFͷΠϯετʔϧ
    w ຊ൪σϓϩΠ؀ڥͷ༻ҙ ྫ(,&

    Ͱ͸࢖ͬͯΈΑ͏

    View full-size slide

  37. 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

    View full-size slide

  38. w NBJOHPΛίϯύΠϧ࣮ߦ͢Δ͚ͩͷαϯϓϧ
    FYBNQMFTHFUUJOHTUBSUFE

    View full-size slide

  39. NBJOHP
    package main
    import (
    "fmt"
    "time"
    )
    func main() {
    for {
    fmt.Println("Hello world!")
    time.Sleep(time.Second * 1)
    }
    }

    View full-size slide

  40. %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 .

    View full-size slide

  41. 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

    View full-size slide

  42. LTQPEZNM
    apiVersion: v1
    kind: Pod
    metadata:
    name: getting-started
    spec:
    containers:
    - name: getting-started
    image: gcr.io/myproj-koyhoge/skaffold-gcb

    View full-size slide

  43. TLB⒎PMEEFW
    Ϗϧυ
    ొ࿥
    σϓϩΠ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide