Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kubernetesの永続化ストレージ基礎
Search
Ryoma Fujiwara
October 18, 2018
Technology
12
6.7k
Kubernetesの永続化ストレージ基礎
Rancher meetup #15で発表したKubernetesの永続化ストレージの必要性と基礎について説明した資料となります。
Ryoma Fujiwara
October 18, 2018
Tweet
Share
More Decks by Ryoma Fujiwara
See All by Ryoma Fujiwara
個人検証アカウントの管理どんな感じでやってますか_JAWSUGランチ共有会発表資料
fufuhu
3
700
AWS OrganizationsとIAM Identity Center, Terraformを連携した権限管理
fufuhu
5
8.5k
過去のセキュリティ系セッション振り返り
fufuhu
2
420
heyにおけるCI/CDの現状と課題
fufuhu
3
1k
heyにおけるSREの大切さ~マルチプロダクト運用の「楽しさ」と「難しさ」および今後の展望~
fufuhu
3
9.6k
STORES決済におけるEC2からECS Fargateへの移行〜無停止要件も添えて〜
fufuhu
3
2.1k
Rancher Harvesterの紹介
fufuhu
4
1.3k
リクルートにおけるクラウドネイティブ実践のための取り組み
fufuhu
1
150
DevOps導入指南2020年度版
fufuhu
1
140
Other Decks in Technology
See All in Technology
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
12
8k
QA Engineer Life @ LINE
line_developers_tw
PRO
0
230
株式会社EventHub・エンジニア採用資料
eventhub
0
2.1k
PHP 9 に備えよ - 動的プロパティ、どうすればいぃ?
taisukearase
0
410
スクラムに出会って「できた」を実感できるようになってきた話 / Scrum makes me feel like I can do it
yayoi_dd
2
120
エムスリーQAチーム紹介資料 / Introduction of M3 QA Team
m3_engineering
1
340
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
1.7k
LINEヤフーのウェブアクセシビリティ
lycorptech_jp
PRO
3
220
汎用ポリシー言語Rego + OPAと認可・検証事例の紹介 / Introduction Rego & OPA for authorization and validation
mizutani
1
200
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
36k
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
16
6.7k
データベース04: SQL (1/3) 単純質問 & 集約演算
trycycle
0
180
Featured
See All Featured
Designing with Data
zakiwarfel
96
4.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
275
13k
A Tale of Four Properties
chriscoyier
153
22k
Learning to Love Humans: Emotional Interface Design
aarron
268
39k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
358
22k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
21
2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
14
1.5k
Facilitating Awesome Meetings
lara
43
5.6k
Documentation Writing (for coders)
carmenintech
60
4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
34
6.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
8
3.5k
The Illustrated Children's Guide to Kubernetes
chrisshort
32
47k
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