环境
1, Kubernetes cluster(两台虚拟机,一台master,一台node)
步骤
1, 安装NFS软件包到k8s集群的每一台机器
yum install nfs-utils rpcbind
2, 安装好后,编辑配置文件(我这里选择了一台node作为NFS server)
vi /etc/exports
/data/nfs *(rw,sync,insecure,no_subtree_check,no_root_squash)
第一个参数是你准备export的目录
第二个参数是客户端IP范围, 我这里选择的接受任何连接
第三个就是NFS的参数
3, 服务加入启动项并启动
systemctl enable rpcbind
systemctl enable nfs
systemctl start rpcbind
systemctl start nfs
4, 参考一下文章, 创建一个nfs client来支持动态创建PV.
https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client
用helm创建,执行这条命令
helm install stable/nfs-client-provisioner --set nfs.server=192.168.30.143 --set nfs.path=/data/nfs
5, 安装好后,自动产生一个stoageclass
NAME PROVISIONER AGE
nfs-client cluster.local/youthful-bronco-nfs-client-provisioner 175m
6, 创建一个PVC,简单如下
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
labels:
app: test-pvc
spec:
storageClassName: nfs-client
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
7,创建PVC后, 会自动bonding到上面StorageClass, 并产生一个PV
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
test-pvc Bound pvc-850e0777-e65b-467b-924b-882eb8d550a5 5Gi RWX nfs-client 39m
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-850e0777-e65b-467b-924b-882eb8d550a5 5Gi RWX Delete Bound default/test-pvc nfs-client 41m