$ k apply -f pv.yaml persistentvolume/host-10m-pv created
$ k get pv -owide NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE VOLUMEMODE host-10m-pv 10Mi RWO Retain Available host-test 40s Filesystem
$ k apply -f pvc.yaml persistentvolumeclaim/host-5m-pvc created
$ k get pvc -owide NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE host-5m-pvc Bound host-10m-pv 10Mi RWO host-test 70s Filesystem
$ k get pv -owide NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE VOLUMEMODE host-10m-pv 10Mi RWO Retain Bound default/host-5m-pvc host-test 4m58s Filesystem
$ k get pvc -owide NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE host-100m-pvc Pending host-test 4s Filesystem
$ k get pv -owide NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE VOLUMEMODE host-10m-pv 10Mi RWO Retain Available host-test 22s Filesystem
$ k get po -owide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES host-pvc-pod 1/1 Running 0 33s 10.10.1.55 mac-worker <none> <none>
$ k exec -it host-pvc-pod -- sh / # cd /tmp/ /tmp # echo zhongmingmao > name.txt /tmp # cat name.txt zhongmingmao /tmp # exit
$ k get no -owide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME mac-master Ready control-plane,master 9d v1.23.3 192.168.191.144 <none> Ubuntu 22.04.2 LTS 5.15.0-75-generic docker://24.0.2 mac-worker Ready <none> 8d v1.23.3 192.168.191.146 <none> Ubuntu 22.04.2 LTS 5.15.0-75-generic docker://20.10.24
登录 mac-worker
1 2
$ cat /tmp/host-10m-pv/name.txt zhongmingmao
重建 Pod,当前集群只有一个 Worker 节点,能重新获取到之前的数据,实现了简单的数据持久化
1 2 3 4 5 6 7 8
$ k delete -f nginx.yaml pod "host-pvc-pod" deleted
$ k apply -f nginx.yaml pod/host-pvc-pod created
$ k exec -it host-pvc-pod -- cat /tmp/name.txt zhongmingmao