NFS

Kubernetes 中最有用的卷类型之一是nfs

NFS 代表网络文件系统——它是一个可以通过网络访问的共享文件系统

NFS 必须已经存在——Kubernetes 不运行 NFS,pod 只能访问它

NFS 之所以有用,有两个原因:

  1. 当 Pod 被销毁时,已经存储在 NFS 中的内容不会被删除。数据是持久的

  2. 一个 NFS 可以同时从多个 pod 访问。NFS 可用于在 Pod 之间共享数据

这对于运行需要在多个应用程序服务器之间共享的文件系统的应用程序非常有用

NFS 安装示例

1.所有节点安装nfs

$ yum install -y nfs-common nfs-utils

2.创建共享目录(master节点)

$ mkdir -p /data/nfsdata

3.授权共享目录(master节点)

$ chmod -R 777 /data/nfsdata

4.修改esports文件(master节点)

$ cat /etc/exports
/data/nfsdata *(rw,no_root_squash,no_all_squash,sync)

5.配置生效(master节点)

$ exportfs -f

6.启动rpcnfs(按顺序)(master节点)

$ systemctl start rpcbind
$ systemctl start nfs
$ systemctl enable rpcbind #开机启动
$ systemctl enable nfs #开机启动

7.检查是否生效(master节点)

$ showmount -e
Export list for k8s-master: /data/nfsdata *

创建PV, PVC

PV 配置文件

image.png

  1. capacity 指定PV的容量为 1G
  2. accessModes 指定访问模式为 ReadWriteOnce
    • ReadWriteOnce – PV 能以 read-write 模式 mount 到单个节点
    • ReadOnlyMany – PV 能以 read-only 模式 mount 到多个节点
    • ReadWriteMany – PV 能以 read-write 模式 mount 到多个节点
  3. persistentVolumeReclaimPolicy 指定当 PV 的回收策略为 Recycle
    • Retain – 需要管理员手工回收
    • Recycle – 清除 PV 中的数据,效果相当于执行 rm -rf /thevolume/*
    • Delete – 删除 Storage Provider 上的对应存储资源,例如 AWS EBS、GCE PD、Azure Disk、OpenStack Cinder Volume 等
  4. storageClassName 指定 PV 的 class 为 nfs。相当于为 PV 设置了一个分类,PVC 可以指定 class 申请相应 class 的 PV
  5. 指定 PV 在 NFS 服务器上对应的目录

image.png

  1. STATUSAvailable 表示就绪,可被PVC绑定

创建PVC

image.png

  1. 访问模式必须与PV一样
  2. 绑定PV的class
  3. 指定需要的容量(< PV容量)

image.png

image.png

STATUSBound表示成功绑定PV

使用

image.png

点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部