1、环境准备
安装nfs服务,是为了保证k8s集群的工作节点,在pod的运行节点切换时可以访问到相同的工作目录
服务器 | 功能 |
---|---|
192.168.1.33 | 服务器端 |
192.168.1.31 | 客户端(k8s集群工作节点) |
192.168.1.32 | 客户端(k8s集群工作节点) |
2、安装nfs服务端
# 在192.168.1.33上进行安装
# 1.安装nfs所需安装包
yum install -y rpcbind nfs-utils
# 2.执行命令,创建 exports 文件
vim /etc/exports
# 增加内容
/data/nfs_root/ *(insecure,rw,sync,no_root_squash)
# 3. 执行以下命令,启动 nfs 服务
# 创建共享目录
mkdir /data/nfs_root
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
exportfs -r
# 4. 检查配置是否生效
exportfs
# 输出结果如下所示
# /data/nfs_root /data/nfs_root
3. 安装nfs客户端–两个工作节点都需要安装
# 1. 安装nfs客户端所需的软件包
yum install -y nfs-utils
# 2. 执行以下命令检查 nfs 服务器端是否有设置共享目录
showmount -e 192.168.1.33
# 显示
Export list for 192.168.1.33:
/data/nfs_root *
# 3. 执行以下命令挂载 nfs 服务器上的共享目录到本机路径 /nfsmount
mkdir /nfsmount
mount -t nfs 192.168.1.33:/data/nfs_root /nfsmount
# 4. 写入一个测试文件
echo "hello nfs server" > /nfsmount/test.txt
# 5. 在 nfs 服务器端上执行以下命令,验证文件写入成功
cat /data/nfs_root/test.txt