Project 3: Frontend + Backend + PostgreSQL PVC
بناء تطبيق مكون من frontend و backend و PostgreSQL، مع PVC لبيانات PostgreSQL وخدمات داخلية واضحة.
المعمارية
Section titled “المعمارية”flowchart LR Browser --> FE[frontend Service] FE --> API[backend Service] API --> DB[(PostgreSQL PVC)]المطلوب
Section titled “المطلوب”- Namespace باسم
project-fullstack. - PostgreSQL Deployment أو StatefulSet مع PVC.
- Backend Deployment يقرأ
DATABASE_URLمن Secret. - Frontend Deployment يتصل بالـ backend Service.
- Services داخلية لكل جزء.
مثال PVC و PostgreSQL
Section titled “مثال PVC و PostgreSQL”postgres.yaml:
apiVersion: v1kind: PersistentVolumeClaimmetadata: name: postgres-data namespace: project-fullstackspec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 1Gi---apiVersion: apps/v1kind: Deploymentmetadata: name: postgres namespace: project-fullstackspec: replicas: 1 selector: matchLabels: app: postgres template: metadata: labels: app: postgres spec: containers: - name: postgres image: postgres:16 env: - name: POSTGRES_PASSWORD value: "demo-password" ports: - name: postgres containerPort: 5432 volumeMounts: - name: data mountPath: /var/lib/postgresql/data resources: requests: cpu: "250m" memory: "512Mi" limits: cpu: "1" memory: "1Gi" volumes: - name: data persistentVolumeClaim: claimName: postgres-data---apiVersion: v1kind: Servicemetadata: name: postgres namespace: project-fullstackspec: selector: app: postgres ports: - name: postgres port: 5432 targetPort: postgresLab: تشغيل PostgreSQL مع PVC
الهدف: تشغيل قاعدة بيانات والتأكد من أن PVC Bound.
kubectl create namespace project-fullstackkubectl apply -f postgres.yamlkubectl -n project-fullstack get pvckubectl -n project-fullstack rollout status deployment/postgreskubectl -n project-fullstack exec deploy/postgres -- psql -U postgres -c "select version();"Expected output
Section titled “Expected output”postgres-data BoundPostgreSQL 16Cleanup
Section titled “Cleanup”kubectl delete namespace project-fullstackAcceptance criteria
Section titled “Acceptance criteria”- PVC بحالة
Bound. - database لا تفقد البيانات عند إعادة إنشاء Pod.
- backend لا يتصل بالـ database عبر Pod IP.
- كل جزء له Service واضح.