題目:建立pod(名稱: ithome-pod-pv),設定使用PersistentVolume(PV)作為儲存,取3Gi,Pod image使用nginx:1.27.1,mountPath: /data;PV(名稱: ithome-pv-volume),容量為10Gi,只能由單一個node做讀寫存取,但不限制pod存取數量
1. PV:儲存池
kubectl apply -f ithome-pv-volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: ithome-pv-volume
labels:
type: local
spec:
capacity: # 資源量
storage: 10Gi
accessModes: #存取模式
- ReadWriteOnce
hostPath: # 錨定
path: "/data"
2. PVC:宣告要從儲存池取多少資源,pod將透過PVC取資源
kubectl apply -f ithome-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ithome-pv-claim
spec: # 規格和PV一致才能配對成功
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
3. Pod:最後才建立pod,設定volume
kubectl apply -f ithome-pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: ithome-pod-pv
name: ithome-pod-pv
spec:
volumes: # Volume設定使用PVC
- name: ithome-storage
persistentVolumeClaim:
claimName: ithome-pv-claim
containers:
- image: nginx
name: ithome-pod-pv
resources: {}
volumeMounts: # 錨定目錄
- mountPath: "/data"
name: ithome-storage
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}