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:删除底层存储。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章