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

Persistent Volumeのはじめの一歩

Persistent Volumeのはじめの一歩

Kubernetes Novice Tokyo #6で発表したスライドです。
https://k8s-novice-jp.connpass.com/event/191555/

Yukinori Sakashita

October 27, 2020
Tweet

More Decks by Yukinori Sakashita

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ ‣ٕज़ݚڀΤϦΞ  ӡ༻؅ཧٕज़  Ϋϥ΢υ  αʔόετϨʔδ  ࣗಈࣗ཯ίϯϐϡʔςΟϯά

     "*.- // ).. #BZFTJBO/FUXPSL  ‣৬ྺ  ೔ཱ੡࡞ॴ 㾎தԝݚڀॴԣ඿ݚڀॴ ओ೚ݚڀһ  㾎ւ֎ݚڀॴ!γϦίϯόϨʔ ϥϘ௕   αʔόϕϯμʔ ςΫχΧϧ4& 2 ࡔԼ޾ಙ ത࢜  :VLJOPSJ4BLBTIJUB 1I% ‣ ϠϑʔגࣜձࣾθοτϥϘגࣜձࣾ ‣ 4/*"೔ຊࢧ෦ٕज़ҕһձ෭ҕһ௕ ‣ 4/*" 64 5FDIOJDBM$PVODJM"EWJTPS
  2. 1FSTJTUFOUͱ͸ ‣ &QIFNFSBM ͸͔ͳ͍ɺ୹໋   1PEͷ࡟আ࠶σϓϩΠͱಉ࣌ʹσʔλ͕ফ͑Δ  FNQUZ%JS XSJUBCMFMBZFSTFUD

    ‣ 1FSTJTUFOU ࣋ଓతɺӬଓੑ   1PE͕࡟আ࠶σϓϩΠ͞Εͯ΋σʔλ͸ফ͑ͳ͍  1FSTJTUFOU7PMVNF 17 5 bin/lib Container App Logic Data
  3. &QIFNFSBM 1FSTJTUFOU -PDBM 1FSTJTUFOU &YUFSOBM σʔλͷอଘ৔ॴ ଱ো֐ੑ 1PE࡟আͰσʔλ΋࡟আ ϊʔυ ΋͘͠͸σΟεΫ

    ࡟আͰ σʔλ΋࡟আ ετϨʔδ ΋͘͠͸7PMVNF ࡟আ Ͱσʔλ΋࡟আ ୅දతͳ ,4ͷϦιʔε FNQUZ%JS 17$17 -PDBM  IPTU1BUI 17$17 σʔλͷอଘ৔ॴ $POUBJOFS 4UPSBHF $POUBJOFS $POUBJOFS $POUBJOFS PS XSJUBCMF MBZFS FNQUZ%JS
  4. #MPDL4UPSBHF 'JMF4UPSBHF 0CKFDU4UPSBHF ΞʔΩςΫνϟ ಛ௃ w಺ଂυϥΠϒͱಉ͡3BXσόΠε wϑΝΠϧγεςϜ͸ࣗ༝ʹબ୒ wωοτϫʔΫυϥΠϒ wϑΝΠϧγεςϜ͸ετϨʔδ೚ ͤɺมߋෆՄ

    wΦϒδΣΫτ୯ҐͰΞΫηε wϑΝΠϧγεςϜʹґଘ͠ͳ͍ ͨΊɺେྔσʔλΛ֨ೲՄೳ σʔλసૹϓϩτίϧ J4$4* /7.FP' /'4 4.# )5514 )551 Ϛ΢ϯτύεͷྫ EFWTEB aaaTIBSFaIPHF IUUQTBBBPSHTUPSBHFIPHF ੑೳ )JHI .JEEMF -PX ओͳ༻్ %# 04 #PPU%JTL ϑΝΠϧͷڞ༗ ࣸਅɺಈը֨ೲ ετϨʔδछผ J4$4* /"44FSWFS /'4 4.# ,74 )55144FSWFS )5514 )PTU )PTU )PTU Ұൠతͳ܏޲Ͱ͋Γ੡඼ʹΑΓมΘΓ·͢ 4$4* 4$4*
  5. #MPDL4UPSBHF 'JMF4UPSBHF 0CKFDU4UPSBHF ΞʔΩςΫνϟ ಛ௃ w಺ଂυϥΠϒͱಉ͡3BXσόΠε wϑΝΠϧγεςϜ͸ࣗ༝ʹબ୒ wωοτϫʔΫυϥΠϒ wϑΝΠϧγεςϜ͸ετϨʔδ೚ ͤɺมߋෆՄ

    wΦϒδΣΫτ୯ҐͰΞΫηε wϑΝΠϧγεςϜʹґଘ͠ͳ͍ ͨΊɺେྔσʔλΛ֨ೲՄೳ σʔλసૹϓϩτίϧ J4$4* /7.FP' /'4 4.# )5514 )551 Ϛ΢ϯτύεͷྫ EFWTEB aaaTIBSFaIPHF IUUQTBBBPSHTUPSBHFIPHF ੑೳ )JHI .JEEMF -PX ओͳ༻్ %# 04 #PPU%JTL ϑΝΠϧͷڞ༗ ࣸਅɺಈը֨ೲ ετϨʔδछผ J4$4* /"44FSWFS /'4 4.# ,74 )55144FSWFS )5514 )PTU )PTU )PTU Ұൠతͳ܏޲Ͱ͋Γ੡඼ʹΑΓมΘΓ·͢ 4$4* 4$4* ,VCFSOFUFTͷ17$17ͷλʔήοτ কདྷαϙʔτͷ Մೳੑ͋Γ˞ ˞,&1IUUQTHJUIVCDPNLVCFSOFUFTFOIBODFNFOUTJTTVFT $04*IUUQTHJUIVCDPNLVCFSOFUFTTJHTDPOUBJOFSPCKFDUTUPSBHFJOUFSGBDFTQFD
  6. σʔλՁ஋ͱಛੑͱอଘ৔ॴ ‣ σʔλͷՁ஋΍ΞϓϦͷಛੑʹԠͯ͡ɺͲ͜ʹอଘ͢Δͷ͔ΛܾΊΔͷ͕ϕλʔ  Ձ஋͸Ϗδωε΍ఏڙαʔϏεͷॏཁ౓Ͱܾ·Δ͜ͱ͕ଟ͍  ಛੑ͸σʔλʹΞΫηε͢ΔΞϓϦ΍ϢʔεέʔεͰܾ·Δ͜ͱ͕ଟ͍ ཁٻੑೳ 3FBE8SJUFͷൺ཰ 3%#͸/'4͕ඇਪ঑͕ଟ͍౳

    3%# .2 /P42- 'JMF ސ٬৘ใ ։ൃɾ ӡ༻ʹඞཁ ࠶ੜ੒Մೳͳσʔλ Ұ࣌తͳσʔλ &QIFNFSBM 1FSTJTUFOU -PDBM 1FSTJTUFOU #ࣾ'JMF Ձ஋ ಛੑ อଘ৔ॴ 1FSTJTUFOU "ࣾ#MPDL 1FSTJTUFOU $ࣾ0CKFDU
  7. ετϨʔδͷϞσϧ ‣ ϕϯμʔχϡʔτϥϧͳϞσϧ  1FSTJTUFOU7PMVNF$MBJN  1FSTJTUFOU7PMVNF  4UPSBHF$MBTT ‣

    ؅ཧऀͱϢʔβͷ໾ׂΛߟྀͨ͠Ϟσϧ ‣ ετϨʔδ૷ஔͷૢ࡞ͳ͠Ͱ7PMVNFΛ ίϯςφʹࣗಈͰϚ΢ϯτ ‣ ओʹϒϩοΫετϨʔδϑΝΠϧ ετϨʔδ͕ର৅ 12 Ϣʔβ ؅ཧऀ
  8. ετϨʔδϦιʔεͷൣғͱݖݶ ‣ 4UPSBHF$MBTT 1FSTJTUFOU7PMVNF͸શͯͷ/BNFTQBDFͰڞ௨ͷϦιʔε  Ϋϥελશମͷ؅ཧऀݖݶ͕ඞཁ  $MVTUFS3PMFͱόΠϯσΟϯά͞ΕͨΞΧ΢ϯτ ‣ 1FSTJTUFOU7PMVNF$MBJN͸/BNFTQBDF͝ͱͷϦιʔε

     /BNFTQBDFEΦϒδΣΫτ΁ͷಡΈॻ͖ͷݖݶ͕ඞཁ  3PMFͱόΠϯσΟϯά͞ΕͨΞΧ΢ϯτ 13 LVCFDUMBQJSFTPVSDFT /".&4)035/".&4"1*(3061/".&41"$&%,*/% QFSTJTUFOUWPMVNFDMBJNTQWDUSVF1FSTJTUFOU7PMVNF$MBJN QFSTJTUFOUWPMVNFTQWGBMTF1FSTJTUFOU7PMVNF TUPSBHFDMBTTFTTDTUPSBHFLTJPGBMTF4UPSBHF$MBTT
  9. ϩοΫϝΧχζϜͷҧ͍ ‣ ϒϩοΫετϨʔδ  -#" ࿦ཧϒϩοΫΞυϨογϯά ͷΞΫηε ͷͨΊɺϩοΫϝΧχζϜΛ͍࣋ͬͯͳ͍  ୆ͷϗετ͔ΒͷΈ8SJUFͱͳΔΑ͏ʹ

    Ϛ΢ϯτ͢Δඞཁ͋Γ ‣ ϑΝΠϧετϨʔδ  ϑΝΠϧ୯ҐͰͷϩοΫϝΧχζϜ͋Γ  0QFO࣌ʹऔಘͨ͠ϩοΫΛଞϗετʹ΋఻ൖ  ෳ਺୆ͷϗετ͔Β3FBE8SJUF͕Մೳ 15 )PTU )PTU )PTU )PTU 3FBE8SJUF 3FBE 3FBE8SJUF 3FBE8SJUF )PTU ͕ഉଞϩοΫͰ ։͍͍ͯΔΑ pMF ϒϩοΫετϨʔδ ϑΝΠϧετϨʔδ
  10. "DDFTT.PEFT 16 /PEF /PEF 3FBE 3FBE 3FBE8SJUF0ODF 380 3FBE0OMZ.BOZ 309

    /PEF /PEF 3FBE8SJUF.BOZ 389 ‣ ͭͷ/PEF͔Β3FBE 8SJUFͰϚ΢ϯτͰ͖Δ ‣ ෳ਺ͷ/PEF͔Β3FBE 0OMZͰϚ΢ϯτͰ͖Δ ‣ ෳ਺ͷ/PEF͔Β3FBE 8SJUFͰϚ΢ϯτͰ͖Δ /PEF 3FBE8SJUF 3FBE8SJUF 3FBE8SJUF
  11. 1FSTJTUFOU7PMVNF QW ‣ 7PMVNFΛද͢Ϧιʔε  4UPSBHFUZQF 4UPSBHF$MBTT໊   4J[F

     "DDFTTNPEFT  3FDMBJNQPMJDZ w 3FUBJO w 3FDZDMF %FQSFDBUFE  w %FMFUF 17
  12. $4* $POUBJOFS4UPSBHF*OUFSGBDF ‣ ίϯςφΦʔέετϨʔγϣϯ޲͚ͷඪ४࢓༷ ‣ ओཁͳίϯςφΦʔέετϨʔγϣϯ͕࠾༻ ,VCFSOFUFT $MPVE'PVOESZ .FTPT %PDLFS

    FUD  ‣ ,VCFSOFUFTͰ͸ʹͯ("αϙʔτ ‣ ,VCFSOFUFTͷιʔεπϦʔ JOUSFF Ͱ؅ཧ͞Ε͍ͯͨετϨʔδ૷ஔʹ ؔ࿈͢Δ࣮૷͕ɺSEϕϯμͰಠࣗʹ։ൃఏڙ͢Δ͜ͱ͕Մೳ ‣ ,VCFSOFUFTͰ͸JOUSFF͸ഇࢭ༧ఆɺ$4*΁ͷҠߦ͕ਪਐத 20
  13. %ZOBNJD1SPWJTJPOJOH 22 ʜ TQFD DPOUBJOFST OBNFNZTRM JNBHFNZTRM ʜ WPMVNF.PVOUT OBNFNZTRMEBUB

    NPVOU1BUIWBSMJCNZTRM WPMVNF$MBJN5FNQMBUFT NFUBEBUB OBNFNZTRMEBUB T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ODF> TUPSBHF$MBTT/BNFHPME SFTPVSDFT SFRVFTUT TUPSBHF(J Storage OS "TTJHO $SFBUF 17
  18. %ZOBNJD1SPWJTJPOJOH 27 ʜ TQFD DPOUBJOFST OBNFNZTRM JNBHFNZTRM ʜ WPMVNF.PVOUT OBNFNZTRMEBUB

    NPVOU1BUIWBSMJCNZTRM WPMVNF$MBJN5FNQMBUFT NFUBEBUB OBNFNZTRMEBUB TQFD BDDFTT.PEFT<3FBE8SJUF0ODF> TUPSBHF$MBTT/BNFHPME SFTPVSDFT SFRVFTUT TUPSBHF(J Storage OS Container Runtime Container .PVOU ɹ17
  19. 4UBUFGVM4FU TUT  35 ‣ 17$17Λศར͔ͭ҆શʹ࢖͏ͳΒ4UBUFGVM4FU͕Φεεϝ ‣ 4UBUFGVM4FUΛ࡟আͯ͠΋4UBUFGVM4FUͱ1PE͕ফ͑ΔͷΈ 17$ 17͸࡟আ͞Εͳ͍

    Φϖϛε๷ࢭ  ‣ ಛ௃  1PE໊ʹ࿈ଓͨ͠φϯόϦϯά FH NZTRM NZTRMʜ   ετϨʔδʹ༏͍͠ಈ࡞ ҆શ   17$Λࣗಈੜ੒ͯ͘͠ΕΔWPMVNF$MBJN5FNQMBUFT ‣ 17$17ͷαΠζ֦ு 7PMVNF&YQBOTJPO Ͱ͸஫ҙ͕ඞཁ˞ ɾɾ ˞$/%5l1FSTJTUFOU7PMVNFͷҰาਐΜͩ࢖͍ํzࢀর IUUQTTQFBLFSEFDLDPNZTBLBTIJUBQFSTJTUFOUWPMVNFGBMTFCVKJOOEBTIJJGBOH
  20. ಛ௃࿈ଓͨ͠φϯόϦϯά ‣ 4UBUFGVM4FU͔Βੜ੒͞ΕΔ1PEͷ໊લ͸ࣗಈͰφϯόϦϯά ‣ 1PEʹ໾ׂΛઃఆ͠қ͍  εΫϦϓτͳͲͰศར 36 LVCFDUMHFUQPE NAME

    READY STATUS RESTARTS AGE mysql-0 2/2 Running 0 69s mysql-1 2/2 Running 0 59s mysql-2 2/2 Running 0 52s NZTRM NZTRM NZTRM 4PVSDF 3FQMJDB 3FQMJDB
  21. ಛ௃ετϨʔδʹ༏͍͠ಈ࡞ ‣ 1PEΛߋ৽͢Δࡍɺඞͣલͷ൪߸ͷ1PEͷॲཧ͕׬͔ྃͯ͠Β࣮ߦ ‣ ετϨʔδͷ%FUBDI͕ߦΘΕͨޙɺ"UUBDI͕࣮ߦ͞ΕΔ͜ͱ͕อূ ‣ %FQMPZNFOUͩͱ"UUBDIʹࣦഊɺσʔλഁյʹܨ͕Δ৔߹͕͋ΔͷͰ஫ҙ 3PMMJOH 6QEBUF FUD

    3VOOJOH 5FSNJOBUJOH $SFBUJOH ಉ࣌ʹൃੜ 38 Ϛ΢ϯτʹࣦഊ΍ ಉҰϑΝΠϧ΁ͷ8SJUF ͕ൃੜ͢ΔϦεΫ͋Γ 3PMMJOH 6QEBUF FUD 3VOOJOH $SFBUJOH ݹ͍1PE͕࡟আޙɺ࡞੒։࢝ 38 QPEYYY QPEYYY QPEZZZ QPE QPE QPE %FQMPZNFOU 4UBUFGVM4FU
  22. ઃఆ಺༰͸ 17$ͱಉ͡ ಛ௃WPMVNF$MBJN5FNQMBUFT ‣ 4UBUFGVM4FUΛσϓϩΠ͢Δͱ1PEͷੜ੒ʹ͋Θͤͯ17$΋ੜ੒ 38 apiVersion: apps/v1 kind: StatefulSet

    metadata: name: mysql … containers: … volumeMounts: - name: data mountPath: /var/lib/mysql … volumeClaimTemplates: - metadata: name: data spec: storageClassName: standard accessModes: [“ReadWriteOnce”]
 resources: requests: storage: 10Gi LVCFDUMHFUQPE NAME READY STATUS RESTARTS AGE mysql-0 2/2 Running 0 156m mysql-1 2/2 Running 0 156m mysql-2 2/2 Running 0 156m LVCFDUMHFUQWD NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE data-mysql-0 Bound pvc-XXX 10Gi RWO standard 164m data-mysql-1 Bound pvc-YYY 10Gi RWO standard 163m data-mysql-2 Bound pvc-ZZZ 10Gi RWO standard 161m LVCFDUMHFUQW NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-xxx 10Gi RWO Delete Bound db/data-mysql-1 standard 165m pvc-yyy 10Gi RWO Delete Bound db/data-mysql-2 standard 163m pvc-zzz 10Gi RWO Delete Bound db/data-mysql-0 standard 166m 17͸17$͕ੜ੒͞ΕΔͱ %ZOBNJD1SPWJTJPOJOH ʹΑΓࣗಈੜ੒ WPMVNF$MBJN5FNQMBUFͷ໊લ 4UBUFGVM4FUͷ໊લ࿈൪ Ͱ17$͕ੜ੒
  23. ·ͱΊ 39 ‣ σʔλͷӬଓԽʹؔ͢Δجຊతͳߟ͑ํΛ঺հ ‣ ,VCFSOFUFTͰͷετϨʔδͷϞσϧͱಈ͖Λ঺հ ‣ 17$17Λศར͔ͭ҆શʹ࢖͏4UBUFGVM4FUʹ͍ͭͯ঺հ ‣ ,VCFSOFUFTͰ͸ɺந৅Խ͞ΕͨϞσϧʹΑΓ

    ετϨʔδΛར༻͢Δͷ͸γϯϓϧͰ؆୯ ‣ ΋͠೉͍͠ͱ͢Ε͹ɺͦ΋ͦ΋ͷεςʔτϑϧΞϓϦ΍ετϨʔδͷӡ༻ εςʔτϑϧΞϓϦ΍ετϨʔδͷӡ༻ܦݧ͕ઙ͍৔߹͸ɺ ॳΊ͔ΒϏδωεΫϦςΟΧϧͳσʔλʹ௅ઓͤͣɺ ࣦͬͯ΋ϏδωεʹӨڹͷগͳ͍σʔλ͔Β௅ઓ͠ϊ΢ϋ΢Λ஝ੵ ͜Ε͔Βεςʔτϑϧ΁௅ઓ͢Δਓ΁ͷҰݴ