Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kubernetesの永続化ストレージ基礎
Search
Ryoma Fujiwara
October 18, 2018
Technology
7.6k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kubernetesの永続化ストレージ基礎
Rancher meetup #15で発表したKubernetesの永続化ストレージの必要性と基礎について説明した資料となります。
Ryoma Fujiwara
October 18, 2018
More Decks by Ryoma Fujiwara
See All by Ryoma Fujiwara
AIと壁打ちしながら進めるコスト管理
fufuhu
2
2k
時間軸から考えるTerraformを使う理由と留意点
fufuhu
16
6.7k
Rancher と Terraform
fufuhu
2
770
なぜ今、Terraformの本を書いたのか? - 著者陣に聞く!『Terraformではじめる実践IaC』登壇資料
fufuhu
4
2.9k
偶発性を好奇心で味方にする
fufuhu
2
1.1k
Harvesterという選択肢 (RancherJP Online Meetup #05)
fufuhu
1
380
個人検証アカウントの管理どんな感じでやってますか_JAWSUGランチ共有会発表資料
fufuhu
3
1.3k
AWS OrganizationsとIAM Identity Center, Terraformを連携した権限管理
fufuhu
5
11k
過去のセキュリティ系セッション振り返り
fufuhu
2
670
Other Decks in Technology
See All in Technology
From Vanilla Kubernetes to a Batteries-Included Platform: Developer Experience at 1,300+ Clusters
yosshi_
0
690
20260906 「AWS運用入門」著者が教える、運用業務への生成AI活用入門
masaruogura
0
260
2026_devsumi_ozono.pdf
o3
3
410
SQL文一行も書けない人事がCortexもろもろを使って人事業務を楽にしてみる
ponponmikankan
1
220
2026/09/10 Spring Bootから Jakarta EE/MicroProfileへの移行
megascus
0
340
日経電子版を支えていく Kasane Design System/fec_fukuoka
nikkei_engineer_recruiting
0
950
TinyGo 開発サイクルを高速化する:Go で作るエミュレータ入門
zozotech
PRO
1
650
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
270
synctest時代のhttptest Go 1.27で変わるHTTPサーバテストの裏側 / go conference2026 synctest and httptest
budougumi0617
1
2.7k
Gitは怖い?共有ワークスペースから始めるSnowflakeチーム開発
coco_se
0
180
多層防御と最⼩権限で実現する、安全なAIエージェント設計パターン
lycorptech_jp
PRO
1
270
Where Is JetBrains AI Heading- — Central CLI, Air Alpha, and the Agentic Development Stack
x5gtrn
PRO
0
160
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Leo the Paperboy
mayatellez
9
2.3k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Design in an AI World
tapps
1
310
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
Test your architecture with Archunit
thirion
2
2.4k
We Are The Robots
honzajavorek
0
360
GraphQLとの向き合い方2022年版
quramy
50
15k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
490
Transcript
Kubernetesの 永続化ストレージ基礎 1
⾃⼰紹介 藤原 涼⾺ (@RYoMa_0923) インフラエンジニア Rancher JPコアメンバー 趣味 勉強会で⾊々喋る ⼦供と遊ぶ
特技 無茶振り対応 いらすとや・ヒューマンピクトグラム2.0の酷使 2 (C)Ryoma Fujiwara, All rights reserved
⽬的 Kubernetesの永続化ボリュームの 必要性 と 基礎 について理解してもらう 3 (C)Ryoma Fujiwara, All
rights reserved
注意 & 懸念事項 4 (C)Ryoma Fujiwara, All rights reserved
注意 & 懸念事項 5 (C)Ryoma Fujiwara, All rights reserved これの品質
注意 & 懸念事項 6 (C)Ryoma Fujiwara, All rights reserved これの品質
⾷物アレルギーで 3⽇前に救急搬送 されてる(ry
まあ、あれだ。 7 (C)Ryoma Fujiwara, All rights reserved
まあ、あれだ。 まさか33もなって ⾷物アレルギー(きくらげ) 追加されるとは思わな かったよ & 現代医療は偉⼤ & お医者さんありがとう 8
(C)Ryoma Fujiwara, All rights reserved
9 (C)Ryoma Fujiwara, All rights reserved 間違いの指摘歓迎
最初に 10 (C)Ryoma Fujiwara, All rights reserved 買った⼈?
最初に 11 (C)Ryoma Fujiwara, All rights reserved 買ってない⼈は 使う予定があるなら ひとまず買いましょう
最初に 12 (C)Ryoma Fujiwara, All rights reserved 7.5 PersistentVolumeClaim 〜
7.9 volumeMountsで利⽤可能なオプション をひととおり理解している⼈ ノシ
最初に 13 (C)Ryoma Fujiwara, All rights reserved あまり追加情報はないですが、 何かしら持って帰って もらえるように頑張ります
⽬的 Kubernetesの永続化ボリュームの 必要性 と 基礎 について理解してもらう 14 (C)Ryoma Fujiwara, All
rights reserved
⽬的 Kubernetesの永続化ボリュームの 必要性 と 基礎 について理解してもらう 15 (C)Ryoma Fujiwara, All
rights reserved その前に
その前にVolumeについておさらい 永続化ボリュームについて理解してもらう前にVolumeに ついてざっくりおさらい 16 (C)Ryoma Fujiwara, All rights reserved Volume
PersistentVolume + PersistentVolumeClaim
その前にVolumeについておさらい 永続化ボリュームについて理解してもらう前にVolumeに ついてざっくりおさらい 17 (C)Ryoma Fujiwara, All rights reserved Volume
PersistentVolume + PersistentVolumeClaim Volumeの課題感がわかれば PersistentVolumeの意義もわかるはず
Volume コンテナにマウントできる(そりゃそうだ) 18 (C)Ryoma Fujiwara, All rights reserved apiVersion: v1
kind: Pod metadata: name: sample-pod spec: containers: - image: nginx:1.12 name: sample-container volumeMounts: - mountPath: /opt name: sample-volume volumes: - name: sample-volume emptyDir: {} sample-pod sample-container sample-volume (/optにマウント)
Volumeの種類 Volumeはプラグインを介していろいろ実装できる 19 (C)Ryoma Fujiwara, All rights reserved https://kubernetes.io/docs/concepts/storage/volumes/#types-of-volumes
Volumeの種類 emptyDir と hostPath Volumeといえばこの2つ 20 (C)Ryoma Fujiwara, All rights
reserved https://kubernetes.io/docs/concepts/storage/volumes/#types-of-volumes いや、違うね!という⽅にはごめんなさい
emptyDir Pod⽤の⼀時的なディスク領域を準備してPodにマウント する。 21 (C)Ryoma Fujiwara, All rights reserved apiVersion:
v1 kind: Pod metadata: name: sample-pod spec: containers: - image: nginx:1.12 name: sample-container volumeMounts: - mountPath: /opt name: sample-volume volumes: - name: sample-volume emptyDir: {} sample-pod sample-container sample-volume (/optにマウント)
emptyDir Podを削除するとVolumeも消える 22 (C)Ryoma Fujiwara, All rights reserved $ kubectl
delete pod/sample-pod - ( - ( ) ) - ( /( ίϯςφ ϘϦϡʔϜ શͯফ͑Δ
emptyDirの使い道の例 単⼀Pod、複数コンテナ時にコンテナ間の ファイル連携などに主に利⽤する 23 (C)Ryoma Fujiwara, All rights reserved apiVersion:
v1 kind: Pod metadata: name: sample-pod spec: containers: - image: updater:1.12 name: updater-container volumeMounts: - mountPath: /opt name: comb-volume - image: update_checker:1.12 name: update-check-container volumeMounts: - mountPath: /mnt name: comb-volume volumes: - name: comb-volume emptyDir: {} sample-pod comb-volume updater-container update-check -container /mnt /opt
emptyDirの使い道の例 単⼀Pod、複数コンテナ時にコンテナ間の ファイル連携などに主に利⽤する 24 (C)Ryoma Fujiwara, All rights reserved sample-pod
comb-volume updater-container update-check -container なにがしか ファイルに書き込む ファイルの更新を 検知して何かする e.g. Amazon S3にアップロードなど
hostPath Kubernetesのノード(≒dockerホスト)のディスク領域を コンテナにマウントする 25 (C)Ryoma Fujiwara, All rights reserved apiVersion:
v1 kind: Pod metadata: name: sample-pod spec: containers: - image: nginx:1.12 name: sample-container volumeMounts: - mountPath: /mnt name: sample-volume volumes: - name: sample-volume hostPath: path: /opt type: DirectoryOrCreate sample-container sample-volume KubernetesのNode /opt /mnt sample-pod k8sのノードの/optをsample-volume として切り出し、sample-containerは これを/mntにマウント
hostPathの使い道(例) なにかしらの理由があってKubernetesのノード側に ファイルを出⼒したい場合に利⽤する 26 (C)Ryoma Fujiwara, All rights reserved sample-container
sample-volume KubernetesのNode /opt /mnt sample-pod
Kubernetesの永続化ボリュームの 必要性 と 基礎 について理解してもらう 27 (C)Ryoma Fujiwara, All rights
reserved
1台構成のKubernetesクラスタの世界 28 (C)Ryoma Fujiwara, All rights reserved
1台構成 + MySQL 1台構成のKubernetesクラスタ + MySQL を考える 29 (C)Ryoma Fujiwara,
All rights reserved
1台構成+MySQL+emptyDir 1台構成のKubernetesクラスタ + MySQL + emptyDir 30 (C)Ryoma Fujiwara, All
rights reserved (Volume) emptyDir Podを消すとVolumeも消える
1台構成+MySQL+emptyDir 1台構成のKubernetesクラスタ + MySQL + emptyDir 31 (C)Ryoma Fujiwara, All
rights reserved (Volume) emptyDir DBとして基本的にはNG (意図的に消えて欲しい場合は別)
1台構成 + MySQL + hostPath 1台構成のKubernetes + MySQL + hostPath
32 (C)Ryoma Fujiwara, All rights reserved (Volume) hostPath よさげ
1台構成 + MySQL + hostPath 1台構成のKubernetes + 複数MySQL + hostPath
33 (C)Ryoma Fujiwara, All rights reserved (Volume) hostPath 複数のMySQLが同じデータファイルを ⾒てしまう可能性⼤(hostPathの管理が超煩雑に) やっぱりダメだったよ…
複数台構成+MySQL+emptyDir or hostPath 複数台構成のKubernetesクラスタ + MySQL + emptyDir or hostPath
34 (C)Ryoma Fujiwara, All rights reserved (Volume) emptyDir or hostPath
複数台構成+MySQL+emptyDir 複数台構成のKubernetesクラスタ + MySQL + hostPath 35 (C)Ryoma Fujiwara, All
rights reserved NodeA NodeB NodeC
複数台構成+MySQL+emptyDir 複数台構成のKubernetesクラスタ + MySQL + hostPath 36 (C)Ryoma Fujiwara, All
rights reserved NodeA NodeB NodeC 起動するたびにデータファイル があったりなかったりなんですが… (期待したデータで起動できたりできなかったり……)
複数台構成+MySQL+emptyDir 複数台構成のKubernetesクラスタ + MySQL + hostPath 37 (C)Ryoma Fujiwara, All
rights reserved NodeA NodeB NodeC NodeAで起動した時だけ うまくいきます
複数台構成+MySQL+emptyDir 複数台構成のKubernetesクラスタ + MySQL + hostPath 38 (C)Ryoma Fujiwara, All
rights reserved NodeA NodeB NodeC NodeAで起動した時だけ うまくいきます DBの正常起動ガチャはふつうやらない (nodeSelectorで頑張れば⽴ち上がるNodeの固定も可能だがあまりしない)
PersistentVolumeの意義 ここまでで出てきた課題への解決策が Persistent (永続的な) Volume (ボリューム) 39 (C)Ryoma Fujiwara, All
rights reserved
Kubernetes Nodeとボリュームを (可能な限り)疎な関係にする ※ネットワーク経由のボリュームを使うのが⼀般的 40 (C)Ryoma Fujiwara, All rights reserved
PersistentVolume Kubernetes Node 疎
結果、どのNodeで起動しても期待した データファイルが得られる 41 (C)Ryoma Fujiwara, All rights reserved PersistentVolume Kubernetes
Nodes どのNodeで起動しても期待した データファイルがあります!感激! ちゃんと ”永続化”できてる
Kubernetesの永続化ボリュームの 必要性 と 基礎 について理解してもらう 42 (C)Ryoma Fujiwara, All rights
reserved
PersistentVolumeの作成 • 名前(オプション) • ラベル • アクセスモード • リクレイムポリシー •
ストレージクラス名 43 (C)Ryoma Fujiwara, All rights reserved apiVersion: v1 kind: PersistentVolume metadata: name: sample-volume labels: type: longhorn-pv environment: dev spec: accessModes: - ReadWriteOnce capacity: storage: 8Gi storageClassName: longhorn persistentVolumeReclaimPolicy: Delete
PersistentVolumeの作成 & 構成要素 • 名前 • ラベル • アクセスモード •
容量 • リクレイムポリシー • ストレージクラス名 44 (C)Ryoma Fujiwara, All rights reserved apiVersion: v1 kind: PersistentVolume metadata: name: sample-pv-volume labels: type: longhorn-pv environment: dev spec: accessModes: - ReadWriteOnce capacity: storage: 8Gi persistentVolumeReclaimPolicy: Delete storageClassName: longhorn ここには出てないものもあるので注意
PersistentVolumeの作成 • 名前 : ⽂字通り • ラベル : PersistentVolumeの分類・識別⼦ •
アクセスモード : 別途説明 • 容量 : ボリュームの容量 • リクレイムポリシー: 別途説明(ボリューム再利⽤時の挙動) • ストレージクラス名: どのストレージを使うか 45 (C)Ryoma Fujiwara, All rights reserved
アクセスモード 3種類ある 46 (C)Ryoma Fujiwara, All rights reserved ① ReadWriteOnce:
単⼀のPodからのみ読み書き可能 ② ReadOnlyMany: 複数のPodからの読み取りアクセスのみ可能 ③ ReadWriteMany: 複数のPodからの読み書きアクセスが可能 PersistentVolume PodA PodB PersistentVolume PodA PodB PersistentVolume PodA PodB
アクセスモード 3種類ある 47 (C)Ryoma Fujiwara, All rights reserved ① ReadWriteOnce:
単⼀のPodからのみ読み書き可能 ② ReadOnlyMany: 複数のPodからの読み取りアクセスのみ可能 ③ ReadWriteMany: 複数のPodからの読み書きアクセスが可能 PersistentVolume PodA PodB PersistentVolume PodA PodB PersistentVolume PodA PodB どのaccessModeが使えるかは、 ボリュームプラグイン次第 https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
リクレイムポリシー PersistentVolumeの利⽤が完了 (=PersistentVolumeClaimが削除された) した際の挙動 48 (C)Ryoma Fujiwara, All rights reserved
① Delete ② Retain ③ Recycle(⾮推奨なので説明しない) PersistentVolumeClaim の削除 PersistentVolume の削除 PersistentVolumeClaim の削除 PersistentVolume の削除 ボリュームはそのまま残る ボリュームは消える データも消える
ストレージクラス名 ストレージクラスを指定することで、 ストレージクラスに対応したprovisionerを介してどのボ リュームプラグインを使ってPersistentVolumeをプロビ ジョニングするかが定まる 49 (C)Ryoma Fujiwara, All rights
reserved StorageClass provisioner Volume Plugin PersistentVolume プロビジョニング
どうやって作成したPersistentVolumeを使う? 50 (C)Ryoma Fujiwara, All rights reserved
どうやって作成したPersistentVolumeを使う? 51 (C)Ryoma Fujiwara, All rights reserved PersistentVolumeClaim
PersistentVolumeClaim PersistentVolumeの所有権を主張して割り当ててもらう 52 (C)Ryoma Fujiwara, All rights reserved https://eikaiwa.dmm.com/blog/21699/ Claim
= 権利(ここでは所有権) を主張する
何を主張するか 53 (C)Ryoma Fujiwara, All rights reserved ラベルが〜〜〜(ラベルセレクタ) で 容量がxxxx、
かつ アクセスモードがyyyy、 で ストレージクラスがzzzz な PersistentVolume をよこせ kind: PersistentVolumeClaim apiVersion: v1 metadata: name: sample-pvc spec: selector: matchLabels: type: "nfs” matchExpressions: - {key: environment, operator: In, values: [stg]} accessModes: - ReadWriteOnce resources: requests: storage: 4Gi storageClassName: longhorn この要求をsample-pvcとする! https://thinkit.co.jp/article/14195?page=0%2C1 ͔ΒҾ༻
Podへのボリュームのマウント 54 (C)Ryoma Fujiwara, All rights reserved 先ほどの主張 (sample-pvc)で得られた ボリュームにnginx-pvcの
名前を与え①、 sample-pvc-podの nginx-containerに マウント②せよ https://thinkit.co.jp/article/14195?page=0%2C1 ͔ΒҾ༻ apiVersion: v1 kind: Pod metadata: name: sample-pvc-pod spec: containers: - name: nginx-container image: nginx ports: - containerPort: 80 name: "http” volumeMounts: - mountPath: "/usr/share/nginx/html" name: nginx-pvc volumes: - name: nginx-pvc persistentVolumeClaim: claimName: sample-pvc ① ②
ざっくりと定義の流れをまとめ 55 (C)Ryoma Fujiwara, All rights reserved PersistentVolume Persistent VolumeClaim
volumes container Podఆٛ
(補⾜)Dynamic Provisioningやリサイズ PersistentVolumeClaimのみで動的にプロビジョニングし たり、PersistentVolumeをリサイズしたりもできますがこ のあたりは書籍・他資料を参照してください 56 (C)Ryoma Fujiwara, All rights
reserved https://speakerdeck.com/masayaaoyama/cndjp8-pvcr 書籍 他資料 https://speakerdeck.com/hhiroshell/kubernetesbiao-zhun- falsesutoreziji-neng-woosaraisiyou
……あれ? 57 (C)Ryoma Fujiwara, All rights reserved
Rancherではどうなのよ? 58
59
できないとでも? 60
もちろんできますとも ただし、事前にストレージの準備等は必要 ボリュームの⼀覧 61 (C)Ryoma Fujiwara, All rights reserved
もちろんできますとも 作成(動的プロビジョニング) 62 (C)Ryoma Fujiwara, All rights reserved
もちろんできますとも !? 63 (C)Ryoma Fujiwara, All rights reserved
もちろんできますとも 作成(動的プロビジョニング) 64 (C)Ryoma Fujiwara, All rights reserved
もちろんできますとも ボリュームできた 65 (C)Ryoma Fujiwara, All rights reserved
Enjoy! 66