NFS
Kubernetes 中最有用的卷类型之一是nfs
NFS 代表网络文件系统——它是一个可以通过网络访问的共享文件系统
NFS 必须已经存在——Kubernetes 不运行 NFS,pod 只能访问它
NFS 之所以有用,有两个原因:
-
当 Pod 被销毁时,已经存储在 NFS 中的内容不会被删除。数据是持久的
-
一个 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.启动rpc和nfs(按顺序)(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 配置文件

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

STATUS为Available表示就绪,可被PVC绑定
创建PVC

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


STATUS为Bound表示成功绑定PV
使用

发表评论 取消回复