K8S 之 使用NFS作爲掛久卷使用POD

一、NFS搭建情況

[root@test-operator nginx_index]# cat /etc/exports
/data/nfs-volume 10.3.153.0/24(rw,no_root_squash)
/data/nfs-volume/nginx_index 10.3.153.0/24(rw,no_root_squash)
[root@test-operator nginx_index]# pwd
/data/nfs-volume/nginx_index
[root@test-operator nginx_index]# cat index.html 
This is NFS Server File!!!!!

二、創建掛久卷

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs                #掛久卷的名稱,pv沒有表空間概念,保存在整個集羣中
spec:
  storageClassName: manual          #用於配匹pvc聲明卷
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany                       #同時多節點掛載讀寫
  persistentVolumeReclaimPolicy: Recycle      #當pod刪除後,保留持久卷內容
  nfs:
    path: /data/nfs-volume/nginx_index
    server: test-operator.cedarhd.com

三、創建掛久卷明

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs
  namespace: test
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: manual               #與持久卷配匹
  resources:
    requests:
      storage: 1Gi

四、創建POD並掛載該掛久卷

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: test
spec:
  containers:
    - image: nginx:alpine
      name: web-server
      volumeMounts:
        - mountPath: /usr/share/nginx/html
          name: nfs                 #所掛載的持久卷的名稱
      ports:
        - containerPort: 80
          protocol: TCP
  volumes:
    - name: nfs                  #持久卷的名稱
      persistentVolumeClaim: 
        claimName: nfs           #持久卷的掛久聲名

五、掛載情況

K8S  之 使用NFS作爲掛久卷使用POD

參考文檔:https://www.jianshu.com/p/1e870a8d6286

六、回收持久卷

通過將persistentVolumeReclaimPolicy設置

Retain:讓Kubernets可以在持久卷從持久卷聲中釋放後仍然能保留它的卷和數據內容,無論在集中刪除持久卷聲明,還是持久卷,數據還是仍然存在,單此卷無法再繼續掛載到其它持久卷聲明中使用,需同時在集羣中刪除持久卷,並再次創建,記住,卷的內容永久不會刪除。
Recycle:當刪除PVC時,刪除卷內容並使卷可用於再次聲明,通過這種方式,持久卷可以被不同的持久卷聲明和pod反覆使用,但該卷的內容會被刪除。
delete:刪除底層存儲。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章