ๆœˆไบฎ

[Kubernetes] PersistentVolume (PV)๊ณผ PersistentVolumeClaim (PVC)๋ž€? ๋ณธ๋ฌธ

docker,kubernetes

[Kubernetes] PersistentVolume (PV)๊ณผ PersistentVolumeClaim (PVC)๋ž€?

๋“€๋„ค 2023. 7. 25. 17:43

๐Ÿ‘พ ์ •์˜

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ PersistentVolume (PV)๊ณผ PersistentVolumeClaim (PVC)์€ ์Šคํ† ๋ฆฌ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜

 

๐Ÿ‘พ ์™œ ์‚ฌ์šฉํ•˜๋Š” ๊ฑธ๊นŒ?

PV, PVC๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ํŒŒ๋“œ(Pod)๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์˜๊ตฌ์ ์œผ๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋•๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ํŒŒ๋“œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์ผ์‹œ์ ์ธ ๋ผ์ดํ”„ ์‚ฌ์ดํด์„ ๊ฐ€์ง€๋ฉฐ, ํŒŒ๋“œ๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ๊ทธ ์•ˆ์˜ ๋ฐ์ดํ„ฐ๋„ ํ•จ๊ป˜ ์‚ฌ๋ผ์ง„๋‹ค. ์ด๋Ÿฐ ํŠน์ง• ๋•Œ๋ฌธ์— ์˜๊ตฌ์ ์ธ ๋ฐ์ดํ„ฐ ์ €์žฅ์„ ์œ„ํ•ด PersistentVolume๊ณผ PersistentVolumeClaim์ด ํ•„์š”ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.

 

์ด๋ฅผ ์ข€ ๋” ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•ด ๋ณด๋ฉด,

  • PersistentVolume (PV)   
- PV๋Š” ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์Šคํ† ๋ฆฌ์ง€์˜ ์–‘์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ด๋Š” ์ผ์ข…์˜ ์Šคํ† ๋ฆฌ์ง€์˜ "๋น„์น˜"์™€ ๊ฐ™์œผ๋ฉฐ, ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ์ž๋Š” ๋‹ค์–‘ํ•œ ์ข…๋ฅ˜์˜ ์Šคํ† ๋ฆฌ์ง€ (์˜ˆ: ๋กœ์ปฌ ๋””์Šคํฌ, ๊ณต์œ  ๋„คํŠธ์›Œํฌ ์Šคํ† ๋ฆฌ์ง€, ํด๋ผ์šฐ๋“œ ์Šคํ† ๋ฆฌ์ง€ ๋“ฑ)๋ฅผ PV๋กœ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋‹ค.
- PV๋Š” ๋ณผ๋ฅจ ์ž์ฒด๋ฅผ ๋œปํ•œ๋‹ค. ํด๋Ÿฌ์Šคํ„ฐ ์•ˆ์—์„œ ์ž์›์œผ๋กœ ๋‹ค๋ฃจ๊ณ , ํŒŒ๋“œ์™€๋Š” ๋ณ„๊ฐœ๋กœ ๊ด€๋ฆฌ๋˜๋ฉฐ ๋ณ„๋„์˜ ์ƒ๋ช… ์ฃผ๊ธฐ๊ฐ€ ์žˆ๋‹ค.
  • PersistentVolumeClaim (PVC)
- PVC๋Š” ์‚ฌ์šฉ์ž๊ฐ€ PV์—์„œ ํ•„์š”ํ•œ ์–‘์˜ ์Šคํ† ๋ฆฌ์ง€๋ฅผ "์ฒญ๊ตฌ"ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์‚ฌ์šฉ์ž๋Š” PVC๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์š”๊ตฌํ•œ ์Šคํ† ๋ฆฌ์ง€ ํฌ๊ธฐ์™€ ๊ฐ€์žฅ ์ž˜ ๋งž๋Š” PV๋ฅผ ์ฐพ์•„ ์—ฐ๊ฒฐํ•œ๋‹ค. ์ด๊ฒƒ์€ ๋งˆ์น˜ "ํ‹ฐ์ผ“"์„ ๊ตฌ๋งคํ•˜์—ฌ "๋น„์น˜"์— ์žˆ๋Š” ์ž๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™๋‹ค.
- ์ž์›์„ ์–ผ๋งˆ๋‚˜ ์‚ฌ์šฉํ•  ๊ฒƒ์ธ์ง€ ์š”์ฒญ(request)ํ•˜๋Š” ๊ฒƒ
- ์‚ฌ์šฉ์ž๊ฐ€ PV์— ํ•˜๋Š” ์š”์ฒญ์ด๋‹ค. ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ ์šฉ๋Ÿ‰์€ ์–ผ๋งˆ์ธ์ง€, ์ฝ๊ธฐ/์“ฐ๊ธฐ๋Š” ์–ด๋–ค ๋ชจ๋“œ๋กœ ์„ค์ •ํ•˜๊ณ  ์‹ถ์€์ง€ ๋“ฑ์„ ์ •ํ•ด์„œ ์š”์ฒญํ•˜๋Š” ๊ฒƒ

https://medium.com/devops-mojo/kubernetes-storage-options-overview-persistent-volumes-pv-claims-pvc-and-storageclass-sc-k8s-storage-df71ca0fccc3

 

๐Ÿ‘พ ์ ์šฉ

์˜ˆ ) nfs๋กœ Nas๋ฅผ ์—ฐ๊ฒฐํ•ด์„œ ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ

 

1.

dev-pv.yml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongodb-dev-nas (์ด๋ฆ„)
spec:
  capacity:
    storage: 10240Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    server: 192.168.10.xxx (์„œ๋ฒ„์ฃผ์†Œ)
    path: /volume/a/b/c (๊ฒฝ๋กœ)

๊ณต์‹๋ฌธ์„œ : https://kubernetes.io/docs/concepts/storage/volumes/#nfs

 

dev-pvc.yml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: (๋„ค์ž„์ŠคํŽ˜์ด์Šค)
  name: mongodb-dev-pvc (์ด๋ฆ„)
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi

๊ณต์‹ : https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims

 

2.

kubectl apply -f dev-pv.yml

kubectl apply -f dev-pvc.yml

3.

kubectl get pv
kubectl get pvc --namespace=[๋„ค์ž„์ŠคํŽ˜์ด์Šค์ด๋ฆ„]

์ฐธ๊ณ 

https://medium.com/devops-mojo/kubernetes-storage-options-overview-persistent-volumes-pv-claims-pvc-and-storageclass-sc-k8s-storage-df71ca0fccc3

https://youngswooyoung.tistory.com/60. (nfs, cifs๊ฐœ๋…)

https://kimjingo.tistory.com/153

 

 

 

 

๋ฐ˜์‘ํ˜•
Comments