1 create nfs
Deploy the nfs service on the kubernetes master node and execute on the master node
#master node install nfs yum -y install nfs-utils #Create nfs directory mkdir -p /nfs/data/ #Modify permission chmod -R 777 /nfs/data #Edit the export file, which is the default configuration file of nfs vim /etc/exports /nfs/data *(rw,no_root_squash,sync) #Configuration takes effect exportfs -r #View effective exportfs #Start rpcbind and nfs services systemctl restart rpcbind && systemctl enable rpcbind systemctl restart nfs && systemctl enable nfs #View the registration status of RPC service rpcinfo -p localhost #showmount test showmount -e 192.168.11.145
All kubernetes node nodes install the client and start up
yum -y install nfs-utils systemctl start nfs && systemctl enable nfs
2 create dynamic storage
How External NFS drivers work The external NFS driver of K8S can be divided into two types according to its working mode (as NFS server or as NFS client): 1.nfs-client: That's what we'll show next. It uses K8S's built-in NFS driver to mount the remote NFS server to the local directory, and then uses itself as the storage provider to associate the storage class. When the user creates the corresponding PVC to apply for PV, the provider compares the requirements of PVC with its own attributes. Once the requirements are met, the sub directory of PV will be created in the locally mounted NFS directory to provide dynamic storage services for Pod. 2.nfs: Unlike NFS client, this driver does not use k8s's NFS driver to mount the remote NFS to the local redistribution, but directly maps the local file to the inside of the container, and then uses it in the container ganesha.nfsd To provide external services for NFS; each time PV is created, the corresponding folder is directly created in the local NFS root directory, and the subdirectory is export ed.
Here's how to create nfs dynamic storage through nfs client
First download the k8s external driver code: https://github.com/kubernetes-incubator/external-storage
Under the NFS client / deploy directory of the directory
One rbac.yaml The file does not need to be modified. This file is used to create RBAC permissions
Two class.yaml The file is used to create a StorageClass. You can modify the name value according to your own needs. In this paper, change the name: managed NFS storage to name: NFS storage
Three deployment.ymal The file is used to create an NFS client provider, as follows
apiVersion: v1 kind: ServiceAccount metadata: name: nfs-client-provisioner --- kind: Deployment apiVersion: extensions/v1beta1 metadata: name: nfs-client-provisioner spec: replicas: 1 strategy: type: Recreate 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 - name: NFS_SERVER value: 10.10.10.60 (Change to your own) - name: NFS_PATH value: /ifs/kubernetes(Change to your own) volumes: - name: nfs-client-root nfs: server: 10.10.10.60(Change to your own) path: /ifs/kubernetes(Change to your own)
The service account creation section needs to be removed because rbac.yaml Already created in the file. Other nfs values are changed to their own values according to their own deployment.
Execute the following command to create
kubectl apply -f rbac.ymal kubectl apply -f class.ymal kubectl apply -f deployment.ymal
Under the NFS client / deploy directory, according to the class.yaml Create StorageClass name modify test-claim.yaml The corresponding value in the file
kubectl apply -f test-claim.yam
[root@k8s-1 ~]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS test-claim Bound pvc-bae936cd-c4c4-11e9-a743-fa163e955143 1Mi RWX nfs-storage
Check that pvc is already bound.