OpenShift Origin v3.7 配置NFS存储

安装nfs服务(服务器和客户端都要装)

yum -y install nfs-utils rpcbind

创建存储目录并设置权限

mkdir /exports/
chown nfsnobody:nfsnobody /exports/ -R

刷新

exportfs -r

启动服务

systemctl start rpcbind
systemctl start nfs-server
systemctl enable rpcbind
systemctl enable nfs-server

测试一下:

mount 192.168.199.161:/exports/ /mnt/
touch /mnt/test
ls /mnt
rm -r /mnt/test
umount /mnt/

创建持久化卷

mkdir -p /exports/pv

创建一个PV模板

cat >  /exports/pv/pv_templete.json  << EOF
{
    "apiVersion": "v1",
    "kind": "PersistentVolume",
    "metadata": {
        "name": "-NAME-"
    },
    "spec": {
        "capacity": {
            "storage": "-CAPACITY-"
        },
        "accessModes": [
            "ReadWriteOnce"
        ],
        "nfs": {
            "path": "/exports/-NAME-",
            "server": "192.168.199.161"
        },
        "persistentVolumeReclaimPolicy": "Recycle"
    }
}
EOF

设置好pv的名称和大小,注意变量NAME的值都是小写

NAME=pv0003
CAPACITY=256Mi

根据模板生成pv文件

cat > /exports/pv/pv_$NAME.json << EOF 
$(cat pv_templete.json|sed "s/-NAME-/$NAME/"|sed "s/-CAPACITY-/$CAPACITY/") 
EOF

创建文件夹

mkdir -p /exports/$NAME
echo "/exports/$NAME *(rw,sync,root_squash)" >> /etc/exports
exportfs -r

执行创建

oc create -f /exports/pv/pv_$NAME.json

persistentVolumeReclaimPolicy的三个选项:
Retian: 保留数据,人工回收持久化卷
Recycle: 通过执行rm -rf删除卷上的所有数据(只有NFS和HostPath支持这种方式)
Delete: 动态删除后端存储,需要IaaS的支持

可以通过远程查看nfs能否访问到
showmount -e (ip地址)
如果远程无法访问到这个nfs,检查防火墙是否启动,有没有打开对应的端口。

你可能感兴趣的:(openshift-v3)