ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Container ရဲ့ filesystem က ephemeral (ယာယီ) ပါ — pod restart/recreate ဖြစ်တိုင်း အထဲက data အားလုံး ပျောက်သွားပါတယ်။ Database ကဲ့သို့ data ကို ထိန်းထားရမယ့် app အတွက် ဒါက ပြဿနာကြီးပါ။ Volume က container ရဲ့ filesystem ပြင်ပက storage ကို ချိတ်ဆက်ပေးပါတယ် — PersistentVolume (PV) က cluster admin ချထားထားတဲ့ storage resource (disk space) ဖြစ်ပြီး, PersistentVolumeClaim (PVC) က app ကနေ 'ဒီလောက်ကြီးတဲ့ storage လိုချင်တယ်' လို့ တောင်းဆိုတဲ့ request ပါ။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Database Pod (ဥပမာ - PostgreSQL) မှာ PVC ချိတ်ဆက်ပေးထားရင်, pod crash ဖြစ်ပြီး ပြန် create ဖြစ်ရင်တောင် PVC ထဲက data (customer records, order history) ကျန်ရှိနေမှာပါ — pod အသစ်က PVC အဟောင်းကို ပြန်ချိတ်ယူပါတယ်။ Local minikube မှာ `hostPath` volume type ကို testing အတွက် သုံးလို့ရပါတယ် (production မှာတော့ cloud disk, ဥပမာ AWS EBS သုံးပါတယ်)။
အတူတူ ကြည့်မယ်
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: db-pod
spec:
containers:
- name: postgres
image: postgres:16
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: db-vol
volumes:
- name: db-vol
persistentVolumeClaim:
claimName: db-storage$ kubectl get pvc db-storage
NAME STATUS VOLUME CAPACITY ACCESS MODES
db-storage Bound pvc-xxxx 1Gi RWO၅ မိနစ် စမ်းကြည့်
PVC တစ်ခု create လုပ်ပြီး Pod ထဲမှာ mount လုပ်ကြည့်ပါ — pod ကို `kubectl delete pod` နဲ့ ဖျက်ပြီး pod အသစ်ပြန်ပေါ်လာချိန် data ကျန်နေလားစစ်ကြည့်ပါ (file တစ်ခု write ထားပြီးမှ)။
သတိလေးတစ်ချက်
PVC ကို ဖျက်လိုက်ရင် (reclaim policy အလိုက်) အထဲက data ကို ပြန်မရနိုင်တော့ချေ ရှိပါတယ် — production database volume ကို ဖျက်ခင် backup ရှိမရှိ အရင်စစ်ပါ။