Backup و Restore باستخدام Velero
الهدف من الدرس
Section titled “الهدف من الدرس”ستتعلم ما الذي يمكن نسخه في Kubernetes، الفرق بين resource backup و volume snapshot، وكيف تصمم restore test.
الفكرة ببساطة
Section titled “الفكرة ببساطة”Velero ينسخ Kubernetes resources ويمكنه التعامل مع volume snapshots حسب provider. لكن backup غير مجرب لا يكفي. يجب تنفيذ restore test دوري.
ماذا ننسخ؟
Section titled “ماذا ننسخ؟”| العنصر | الطريقة |
|---|---|
| Deployments و Services و ConfigMaps | Kubernetes resource backup |
| Secrets | resource backup مع تشفير وحماية التخزين |
| PVC data | CSI snapshots أو file-system backup |
| قواعد البيانات | backup منطقي من database غالبا بجانب Velero |
أوامر Velero
Section titled “أوامر Velero”velero backup create web-backup --include-namespaces web-prodvelero backup describe web-backupvelero backup logs web-backupvelero restore create web-restore --from-backup web-backupvelero restore describe web-restoreExpected output:
Backup completed with status: CompletedRestore completed with status: Completedخطة restore test
Section titled “خطة restore test”flowchart LR B[Create Backup] --> N[New Namespace] N --> R[Restore] R --> V[Verify App] V --> D[Document RTO/RPO]YAML تطبيق بسيط للنسخ
Section titled “YAML تطبيق بسيط للنسخ”apiVersion: v1kind: Namespacemetadata: name: web-prod---apiVersion: v1kind: ConfigMapmetadata: name: app-config namespace: web-proddata: APP_MODE: "prod"Lab: تصميم restore test
الهدف: إنشاء backup لnamespace صغير، ثم كتابة خطوات restore والتحقق.
Prerequisites
Section titled “Prerequisites”- Velero مثبت ومضبوط مع object storage.
kubectl apply -f web-prod.yamlvelero backup create web-prod-test --include-namespaces web-prodvelero backup describe web-prod-testvelero restore create web-prod-restore --from-backup web-prod-testvelero restore describe web-prod-restoreExpected output
Section titled “Expected output”Phase: CompletedCleanup
Section titled “Cleanup”kubectl delete namespace web-prodvelero backup delete web-prod-testأخطاء شائعة
Section titled “أخطاء شائعة”| الخطأ | النتيجة |
|---|---|
| نسخ الموارد فقط ونسيان data | التطبيق يعود بدون بيانات |
| عدم تشفير backup storage | تسريب Secrets |
| عدم اختبار restore | اكتشاف الفشل أثناء الكارثة |