建立PVC沒有意外要透過設定檔
#postgres-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pvc
spec:
  accessModes:
      - ReadWriteOnce
  resources:
      requests:
          storage: 2Gi #要2GB
Access Mode有三種
透過kubectl建立PVC
kubectl apply -f postgres-pvc.yaml
在spec下新增volumes屬性,並mount
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: postgres-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      component: pgdb
  template:
    metadata:
      labels:
        component: pgdb
    spec:
      volumes:
        - name: pgdb-storage
          claimName: postgres-pvc # 要match volume的metadata name  
      containers:
        - name: postgres
          image: postgres
          ports:
            - containerPort: 5432
          volumeMounts:
            - name: pgdb-storage # 要跟上面的volumes下的name match
              mountPath: /var/lib/postgresql/data # 指定db儲存資料檔的路徑
              subPath: postgres  # 把container下的mountPath copy到對應到volume下的資料夾
套用設定檔
kubectl apply -f postgres-deployment.yaml
詳細PVC原理還在消化中,明天繼續