Volumes و PV و PVC
لماذا نحتاج Storage؟
Section titled “لماذا نحتاج Storage؟”Container مؤقت. لو كتب ملفات داخله ثم تم حذفه، قد تضيع الملفات. لذلك نستخدم Volume.
Volume
Section titled “Volume”Volume مساحة تخزين تركب داخل Pod.
volumes: - name: cache emptyDir: {}emptyDir يعيش مع Pod فقط. لو حذف Pod، يحذف التخزين.
PersistentVolume و PersistentVolumeClaim
Section titled “PersistentVolume و PersistentVolumeClaim”PersistentVolumeهو التخزين المتاح في Cluster.PersistentVolumeClaimهو طلب تخزين يقدمه التطبيق.
PVC بسيط
Section titled “PVC بسيط”apiVersion: v1kind: PersistentVolumeClaimmetadata: name: dataspec: accessModes: - ReadWriteOnce resources: requests: storage: 1Giاستخدام PVC داخل Pod
Section titled “استخدام PVC داخل Pod”volumeMounts: - name: data mountPath: /datavolumes: - name: data persistentVolumeClaim: claimName: dataStorageClass
Section titled “StorageClass”StorageClass يحدد طريقة إنشاء التخزين. في Cloud قد ينشئ disk تلقائيا.
kubectl get storageclassAccess Modes
Section titled “Access Modes”| الوضع | المعنى |
|---|---|
ReadWriteOnce | يركب للقراءة والكتابة بواسطة Node واحدة |
ReadOnlyMany | يركب للقراءة فقط بواسطة أكثر من Node |
ReadWriteMany | يركب للقراءة والكتابة بواسطة أكثر من Node |
Lab: PVC عملي
الهدف: إنشاء PVC وتركيبه داخل Pod وكتابة ملف.
أنشئ PVC ثم Pod يستخدمه، واكتب ملفا في /data. احذف Pod وأعد إنشاءه بنفس PVC ثم تأكد أن الملف موجود.