Get the App
SLTechnology News&Howtos  ›  Servers  › 

NFS-Client-Provisioner deployment

Shulou Source: shulou.com Published: 2022-06-03 01:42:29 10月04日 Update

The original purpose of deploying NFS-Client Provisioner is to automatically create a PV that meets the requirements of PVC.

First of all, you must have your own NFS Server and the K8s cluster can access it properly.

After that, apply the following yaml file on k8s master:

1 RBAC.yaml

ApiVersion: v1kind: ServiceAccountmetadata: name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: nfs-client-provisioner---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata: nfs-client-provisioner-runnerrules:-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: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata: name: run-nfs-client-provisionersubjects:-kind: ServiceAccount name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: nfs-client-provisionerroleRef: kind: ClusterRole name: nfs-client-provisioner-runner apiGroup: rbac.authorization.k8s.io---kind: RoleapiVersion: rbac.authorization.k8s.io/v1metadata: name: leader-locking-nfs-client-provisioner # replace With namespace where provisioner is deployed namespace: nfs-client-provisionerrules:-apiGroups: [""] resources: ["endpoints"] verbs: ["get" "list", "watch", "create", "update", "patch"]-kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata: name: leader-locking-nfs-client-provisionersubjects:-kind: ServiceAccount name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: nfs-client-provisionerroleRef: kind: Role name: leader-locking-nfs-client-provisioner apiGroup: rbac.authorization.k8s.io

2 Deployment.yaml

ApiVersion: apps/v1kind: Deploymentmetadata: name: nfs-client-provisioner labels: app: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: defaultspec: replicas: 1 selector: matchLabels: app: nfs-client-provisioner 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: zbb.test/nfs-name: NFS_SERVER value: 10.0 .0.31-name: NFS_PATH value: / netshare volumes:-name: nfs-client-root nfs: server: 10.0.0.31 path: / netshare

Pay attention to modifying the parameters about NFS Server in env and volumes

3 storageclass.yaml

ApiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: managed-nfs-storageprovisioner: zbb.test/nfs # or choose another name, must match deployment's env PROVISIONER_NAME'parameters: archiveOnDelete: "false"

Note:

1) the provisioner in storageclass must be consistent with the definition in deployment!

2) if you do not deploy nfs-client-provisioner to the default namespace, you need to change all the namespace marked with "# replace with namespace where provisioner is deployed" to the target namespace name

3) the name of Storagelass can be changed to what you want.

View the deployed Storagelass:

# kubectl get storageclass# kubectl get cs

(reference) set the storageclass of managednfs-storage to the default storage backend of kubernetes:

# kubectl patch storageclass managed-nfs-storage-p'{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "true"}}'

As a result, the deployment is complete, and a test example is given below:

4 test-pvc.yaml

Kind: PersistentVolumeClaimapiVersion: v1metadata: name: test-claim annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" spec: accessModes:-ReadWriteMany resources: requests: storage: 1Mi

5 test-pod.yaml

Kind: PodapiVersion: v1metadata: name: test-podspec: containers:-name: test-pod image: busybox:1.24 command:-"/ bin/sh" args:-"- c"-"touch / mnt/SUCCESS & & exit 0 | | exit 1" volumeMounts:-name: nfs-pvc mountPath: "/ mnt" restartPolicy: "Never" volumes:-name: nfs-pvc persistentVolumeClaim: claimName: test-claim

At this point, you can query the test results and the test is complete.

After that, you can use NFS to dynamically supply PV, without the need to create it manually.

Test platform: kubernetes 1.16.3

OS: CentOS Linux release 7.7.1908 (Core)

Reference:

Https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client

Https://www.cnblogs.com/robinunix/p/11133032.html

I would like to express my thanks to the authors of the reference materials!

Tags: Test name reference reference material consistency author original intention dynamic parameter that is platform manual file thus goal example space result cluster Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia Shulou Technology Microsoft MySQL