K8S接入NFS存储
2026-09-30 23:45:05 一、部署nfs服务端 安装nfs服务 ubuntu/debian sudo apt update sudo apt install nfs-kernel-server -y centos/rhel / rocky / almalinux sudo dnf install -y nfs-utils 创建共享目录 sudo mkdir -p 路径及目录名 配置nfs配置文件 sudo vim /etc/exports 增加以下内容 /opt/nfs x.x.x.x/xx(rw,sync,no_subtree_check,no_root_squash) # x.x.x.x/xx替换为需要访问nfs的网段或地址 参数说明: 参数说明rw客户端可读写ro客户端只读sync数据同步写入磁盘,更安全async数据异步写入,性能好但是有一定风险no_subtree_check不检查子目录,推荐开启root_squash客户端 root 用户映射为匿名用户no_root_squash客户端 root 用户保留 root 权限,风险较高all_squash所有用户都映射为匿名用户anonuid/anongid指定匿名用户 uid/gid 应用配置 sudo exportfs -rav 重启服务并设置开机自启动 ubuntu/debian sudo systemctl restart nfs-kernel-server sudo systemctl enable nfs-kernel-server sudo systemctl status nfs-kernel-server centos / rhel / rocky / almalinux sudo systemctl enable --now nfs-server sudo systemctl status nfs-server 安全配置(内网可忽略) 放通防火墙 ubuntu/debian sudo ufw allow from 192.168.1.0/24 to any port 2049 proto tcp sudo ufw allow from 192.168.1.0/24 to any port 2049 proto udp sudo ufw allow from 192.168.1.0/24 to any port 111 proto tcp sudo ufw allow from 192.168.1.0/24 to any port 111 proto udp sudo ufw allow from 192.168.1.0/24 to any port 20048 proto tcp sudo ufw allow from 192.168.1.0/24 to any port 20048 proto udp 或者