k8s之PVC+PV+Pod

71 阅读1分钟

1. PersistentVolumeClaim (PVC) - pvc.yml

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

2. PersistentVolume (PV) - pv.yml

yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv1
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "E:\coursera\volume"
  storageClassName: manual

请注意,hostPath 路径设置为 E:\\coursera\\volume,确保该路径在您的 Windows 主机上存在并且具有适当的权限。

3. Pod - pod.yml

yaml复制
apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mycontainer
    image: nigelpoulton/k8sbook:edge
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - mountPath: "/data"
      name: myvolume
  volumes:
  - name: myvolume
    persistentVolumeClaim:
      claimName: pvc1
#应用配置
kubectl apply -f pvc.yml
kubectl apply -f pv.yml
kubectl apply -f pod.yml

#使用命令查看状态
kubectl get pvc pvc1
kubectl get pv pv
kubectl get pod mypod --watch
  • 尤其是PVC必须是STATUS=BOUND才是绑定状态 image.png