nfs服務(wù)器搭建
yum -y install nfs-utils rpcbind
驗證:
rpm -qa nfs-utils
在服務(wù)端創(chuàng)建一個共享目錄 /nfs(目錄可自定義)
mkdir /nfs
chmod 666 /nfs
修改 NFS 配置文件 vim /etc/exports
vim /etc/exports
/nfs *(rw,sync,insecure,no_subtree_check,no_root_squash)
#重載數(shù)據(jù)
exportfs -rv
參數(shù)說明:
/nfs 欲共享出去的目錄谢澈,也就是想共享到網(wǎng)絡(luò)中的文件系統(tǒng)
* 可設(shè)置網(wǎng)段、IP、* 表示允許掛在的客戶端
(ro,sync,insecure,no_root_squash) 設(shè)置 /nfs目錄允許所有客戶端只讀掛載。
更多參數(shù)說明可參考:https://blog.csdn.net/sj349781478/article/details/79970739
# 啟動rpc
systemctl start rpcbind
systemctl start nfs
#設(shè)置開機啟動
systemctl enable rpcbind
systemctl enable nfs
狀態(tài)查看
systemctl status rpcbind
systemctl status nfs
部署StorageClass
下載部署文件
for file in class.yaml deployment.yaml rbac.yaml test-claim.yaml ; do wget https://raw.githubusercontent.com/kubernetes-incubator/external-storage/master/nfs-client/deploy/$file ; done
以下為原文件
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
storageclass.kubernetes.io/is-default-class: "true" # 設(shè)置為default StorageClass
name: managed-nfs-storage
provisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
archiveOnDelete: "false"
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nfs-client-provisioner-runner
rules:
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: run-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: ClusterRole
name: nfs-client-provisioner-runner
apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: Role
name: leader-locking-nfs-client-provisioner
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-client-provisioner
labels:
app: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-client-provisioner
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccountName: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: quay.io/external_storage/nfs-client-provisioner:latest
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: fuseim.pri/ifs # nfs服務(wù)地址
- name: NFS_SERVER
value: 192.168.194.129 # nfs服務(wù)地址
- name: NFS_PATH
value: /nfs # nfs共享目路徑
volumes:
- name: nfs-client-root
nfs:
server: 192.168.194.129 # nfs服務(wù)地址
path: /nfs # nfs共享目路徑
結(jié)果查看
測試
創(chuàng)建pvc
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: myclaim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 200Mi
storageClassName: # 不指定會調(diào)用默認StorageClass