[Kubernetes] ์ ์ฅ ๋ณผ๋ฅจ(Storage Volume)
๐ ๋ค์ด๊ฐ๋ฉฐ
์ด๋ฒ ๊ธ์์๋ ์ฟ ๋ฒ๋คํฐ์ค์ ์คํ ๋ฆฌ์ง ๋ณผ๋ฅจ(Volume)์ ์ ๋ฆฌํ๋ค. ํ๋์ ์ปจํ ์ด๋๋ ์ฌ์์๋๋ฉด ๋ฐ์ดํฐ๊ฐ ์ฌ๋ผ์ง๋ฏ๋ก, ๋ณผ๋ฅจ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ง์ ์ ์ฅํ๊ณ ๊ณต์ ํ๋ค. ์์ ๋ณผ๋ฅจ(emptyDir)๋ถํฐ PV/PVC, ๋์ ํ ๋น(StorageClass), NFS๊น์ง ์ดํด๋ณธ๋ค.
์ ๋ณผ๋ฅจ์ธ๊ฐ? ์ปจํ ์ด๋ ํ์ผ์์คํ ์ ์ผ์์ (ephemeral)์ด๋ผ, ์ฌ์์ํ๋ฉด ์ด๊ธฐํ๋๋ค. ๋ฐ์ดํฐ๋ฅผ ์งํค๊ฑฐ๋ ์ปจํ ์ด๋ ๊ฐ์ ๊ณต์ ํ๋ ค๋ฉด ๋ณผ๋ฅจ์ ๋ง์ดํธํด์ผ ํ๋ค.
1. ๋ณผ๋ฅจ ์ ํ ๊ฐ์
| ์ ํ | ์๋ช | ์ฉ๋ |
|---|---|---|
| emptyDir | ํ๋์ ํจ๊ป(์ญ์ ์ ์๋ฉธ) | ์ปจํ ์ด๋ ๊ฐ ์์ ๊ณต์ |
| hostPath | ๋ ธ๋์ ์ข ์ | ํธ์คํธ ํ์ผ์์คํ ์ ๊ทผ |
| PV / PVC | ํ๋์ ๋ ๋ฆฝ | ์๊ตฌ ์ ์ฅ(ํต์ฌ) |
| StorageClass | ๋์ | PV ์๋ ์์ฑ |
2. emptyDir โ ์์ ๊ณต์
ํ๋ ์์ฑ ์ ๋น ๋๋ ํฐ๋ฆฌ๊ฐ ์๊ธฐ๊ณ , ํ๋๊ฐ ์ญ์ ๋๋ฉด ํจ๊ป ์ฌ๋ผ์ง๋ค. ํ ํ๋ ๋ด ์ฌ๋ฌ ์ปจํ ์ด๋๊ฐ ๋ฐ์ดํฐ๋ฅผ ๊ณต์ ํ ๋ ์ ์ฉํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Pod
metadata:
name: temp-pod1
spec:
volumes:
- name: temp-vol
emptyDir: {}
containers:
- name: container1
image: ubuntu:14.04
volumeMounts:
- name: temp-vol
mountPath: /mount1
- name: container2
image: ubuntu:14.04
volumeMounts:
- name: temp-vol
mountPath: /mount2
๋ ์ปจํ
์ด๋๊ฐ ๊ฐ์ emptyDir์ /mount1ยท/mount2์ ๋ง์ดํธํด ๋ฐ์ดํฐ๋ฅผ ๊ณต์ ํ๋ค.
3. hostPath โ ๋ ธ๋ ํ์ผ์์คํ
ํธ์คํธ ๋ ธ๋์ ๊ฒฝ๋ก๋ฅผ ํ๋์ ๋ง์ดํธํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apiVersion: v1
kind: Pod
metadata:
name: host-pod1
spec:
containers:
- name: container
image: ubuntu:20.04
volumeMounts:
- name: host-path
mountPath: /mnt/host
volumes:
- name: host-path
hostPath:
path: /data
type: DirectoryOrCreate
โ ๏ธ hostPath๋ ๋ ธ๋์ ์ข ์์ ์ด๋ผ, ํ๋๊ฐ ๋ค๋ฅธ ๋ ธ๋๋ก ์ฎ๊ฒจ๊ฐ๋ฉด ๋ฐ์ดํฐ๋ฅผ ๋ชป ์ฐพ๋๋ค. ํน์ ๋ ธ๋์ ํ์ผ์ ์ ๊ทผํด์ผ ํ๋ ํน์ํ ๊ฒฝ์ฐ์๋ง ์ฐ๊ณ , ์ผ๋ฐ์ ์ธ ์๊ตฌ ์ ์ฅ์๋ PV/PVC๋ฅผ ์ฐ๋ ๊ฒ์ด ์์ ํ๋ค.
4. PV & PVC โ ์๊ตฌ ์ ์ฅ์ ํต์ฌ
PV(๊ด๋ฆฌ์๊ฐ ์ ๊ณตํ๋ ์ ์ฅ์) โ PVC(์ฌ์ฉ์์ ์์ฒญ)๋ก ์ ์ฅ์๋ฅผ ์ถ์ํํ๋ค. ์ฌ์ฉ์๋ ์ ์ฅ์ ๋ด๋ถ ๊ตฌํ์ ๋ชฐ๋ผ๋ PVC๋ก โ1Gi ์ฃผ์ธ์โ๋ผ๊ณ ์์ฒญ๋ง ํ๋ฉด ๋๋ค.
flowchart LR
Admin["๐ค ๊ด๋ฆฌ์"] -- ์์ฑ --> PV[("๐พ PV<br/>์ค์ ์ ์ฅ์")]
User["๐จโ๐ป ์ฌ์ฉ์"] -- ์์ฒญ --> PVC["๐ PVC<br/>(1Gi ์์ฒญ)"]
PVC -. ๋ฐ์ธ๋ฉ .-> PV
Pod["๐ฆ Pod"] -- ๋ง์ดํธ --> PVC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# PV โ ๊ด๋ฆฌ์๊ฐ ์ ๊ณต
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv1
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: ""
local:
path: /mnt/data
---
# PVC โ ์ฌ์ฉ์๊ฐ ์์ฒญ
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: ""
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# ํ๋์์ PVC ์ฌ์ฉ
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: myapp
image: nginx
volumeMounts:
- name: mypvc
mountPath: /usr/share/nginx/html
volumes:
- name: mypvc
persistentVolumeClaim:
claimName: pvc1
๐ก PV/PVC ๋ถ๋ฆฌ์ ์ด์ โ ๊ฐ๋ฐ์(์ฌ์ฉ์)๋ ์ ์ฅ์๊ฐ EBS์ธ์ง NFS์ธ์ง ๋ชฐ๋ผ๋ ๋๋ค. โ์ผ๋ง๋ ํ์ํ์ง(PVC)โ๋ง ์ ์ธํ๋ฉด, ๊ด๋ฆฌ์๊ฐ ์ค๋นํ PV์ ๋ฐ์ธ๋ฉ๋๋ค. ์ธํ๋ผ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ด์ฌ์ฌ๋ฅผ ๊น๋ํ๊ฒ ๋ถ๋ฆฌํ๋ ์ค๊ณ๋ค.
5. StorageClass โ ๋์ ํ ๋น
PV๋ฅผ ๋ฏธ๋ฆฌ ๋ง๋ค์ด๋์ง ์๊ณ , PVC ์์ฒญ ์ ์๋์ผ๋ก PV๋ฅผ ์์ฑํ๋ค.
1
2
3
4
5
6
7
8
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-standard
replication-type: none
๐ก ์ ์ vs ๋์ โ ์ ์ ์ ๊ด๋ฆฌ์๊ฐ PV๋ฅผ ๋ฏธ๋ฆฌ ๋ง๋ค์ด๋๋ ๋ฐฉ์, ๋์ ์ StorageClass๊ฐ ์์ฒญ ์ ์ฆ์์์ ๋ง๋๋ ๋ฐฉ์์ด๋ค. ํด๋ผ์ฐ๋(EBSยทGCE PD)์์๋ ๋์ ํ ๋น์ด ํ์ค์ด๋ผ, ๊ด๋ฆฌ์๊ฐ ๋งค๋ฒ PV๋ฅผ ๋ง๋ค ํ์๊ฐ ์๋ค.
6. NFS โ ์ฌ๋ฌ ๋ ธ๋ ๊ณต์
์ฌ๋ฌ ๋
ธ๋๊ฐ ๋์์ ์ฝ๊ณ ์ฐ๋(ReadWriteMany) ๊ณต์ ์คํ ๋ฆฌ์ง๊ฐ ํ์ํ๋ฉด NFS๋ฅผ ์ด๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
path: /data
server: nfs-server.example.com
๐ก ์ ๊ทผ ๋ชจ๋ ์ฐจ์ด โ
ReadWriteOnce(RWO)๋ ํ ๋ ธ๋๋ง,ReadWriteMany(RWX)๋ ์ฌ๋ฌ ๋ ธ๋๊ฐ ๋์์ ๋ง์ดํธํ ์ ์๋ค. EBS๋ RWO, NFSยทEFS๋ RWX๋ฅผ ์ง์ํ๋ค. ์ฌ๋ฌ ํ๋๊ฐ ๊ฐ์ ํ์ผ์ ๊ณต์ ํด์ผ ํ๋ฉด RWX๊ฐ ํ์ํ๋ค.
๐ ์ ๋ฆฌ
1
2
3
4
5
6
์ฟ ๋ฒ๋คํฐ์ค ์คํ ๋ฆฌ์ง
โโ emptyDir ํ๋ ์๋ช
์์(์ปจํ
์ด๋ ๊ฐ ๊ณต์ )
โโ hostPath ๋
ธ๋ ๊ฒฝ๋ก(๋
ธ๋ ์ข
์)
โโ PV/PVC ์๊ตฌ ์ ์ฅ(์ ๊ณต vs ์์ฒญ ๋ถ๋ฆฌ)
โโ StorageClass ๋์ PV ์๋ ์์ฑ
โโ NFS/RWX ์ฌ๋ฌ ๋
ธ๋ ๋์ ๊ณต์
| ๊ฐ๋ | ํ ์ค ์ ์ |
|---|---|
| PV / PVC | ์ ์ฅ์ ์ ๊ณต / ์์ฒญ |
| StorageClass | ๋์ ํ๋ก๋น์ ๋ |
| RWO / RWX | ๋จ์ผ / ๋ค์ค ๋ ธ๋ ๋ง์ดํธ |
์คํ ๋ฆฌ์ง์ ํต์ฌ์ PV/PVC๋ก ์ ์ฅ์๋ฅผ ์ถ์ํํ๊ณ , ํด๋ผ์ฐ๋์์๋ StorageClass๋ก ๋์ ํ ๋นํ๋ ๊ฒ์ด๋ค. ์ฌ์ฉ์๋ โ์ผ๋ง๋ ํ์ํ์งโ๋ง ์ ์ธํ๋ฉด ๋๋๋ก ์ค๊ณ๋ ์ ์ด ์ฟ ๋ฒ๋คํฐ์ค๋ต๋ค.
Comments powered by Disqus.