[Kubernetes (K8S)] Helm install nfs-client-provisioner within Kubernetes (K8S)

helm-nfs-server-provisioner-example

NFS Server Provisioner

The NFS client provisioner - https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client is an automatic provisioner for Kubernetes that uses your already configured NFS server, automatically creating Persistent Volumes.

This chart will deploy the Kubernetes nfs provisioner. This provisioner is intended for connecting to a pre-existing NFS server, and not includes a built in NFS server. If you want a built in NFS Server, please consider using the nfs-client-provisioner - https://github.com/helm/charts/tree/master/stable/nfs-client-provisioner instead.

This article is about how to use Helm to install nfs-client-provisioner on Kubernetes (K8S).


As of Nov 13, 2020, charts in this repo will no longer be updated. For more information, see the Helm Charts Deprecation and Archive Notice, and Update.


You can use Azure Helm mirror - http://mirror.azure.cn/kubernetes/charts/ to replace https://kubernetes-charts.storage.googleapis.com

Prerequisites

  • Kubernetes (K8S)
    Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

  • Helm
    Helm is the best way to find, share, and use software built for Kubernetes.

  • NFS packages and rpcbind.service
    A Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally.

    The rpcbind service uses TCP wrappers for access control, and access control rules for rpcbind affect all RPC-based services(Such as NFS).

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # CentOS
    # Install NFS utils.
    $ sudo yum install nfs-utils -y

    # Start and enable rpcbind.service
    $ sudo systemctl start rpcbind && sudo systemctl enable rpcbind

    # Start and enable rpc-statd.service
    $ sudo systemctl start rpc-statd && sudo systemctl enable rpc-statd
  • Pre-existing NFS server

    You must have a pre-existing NFS server installed according to NFS Server and Client Installation on CentOS 7 - https://www.howtoforge.com/nfs-server-and-client-on-centos-7, or use which is provided by the third-party vendors(such as [5] File Storage NAS: Reliable Network Attached Storage - Alibaba Cloud - https://www.alibabacloud.com/product/nas).

Install

Helm install nfs-client-provisioner into nfs-client-provisioner or your other namespace.

1
2
3
4
5
6
7
8
9
10
11
12
# crate namespace:
$ kubectl create namespace nfs-client-provisioner

# Add the Stable Helm repository:
$ helm repo add stable http://mirror.azure.cn/kubernetes/charts/
# (Deprecation) $ helm repo add stable https://kubernetes-charts.storage.googleapis.com

# Update your local Helm chart repository cache:
$ helm repo update

# To install Helm chart:
$ helm install nfs-client-provisioner stable/nfs-client-provisioner --namespace nfs-client-provisioner -f values.yaml

See Helm release about nfs-client-provisioner

1
2
3
$ helm list --namespace nfs-client-provisioner
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
nfs-client-provisioner nfs-client-provisioner 1 2020-10-17 00:06:55.701473 +0800 +0800 deployed nfs-client-provisioner-1.1.1 2.3.0

See pods about nfs-client-provisioner.

1
2
3
$ kubectl get pods -n nfs-client-provisioner
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-0 1/1 Running 0 24h

Custom Values.yaml

Edit values.yaml and replace content within {{ }}.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# values.yaml

# charts/values.yaml at master · helm/charts · GitHub
# https://github.com/helm/charts/blob/master/stable/nfs-client-provisioner/values.yaml

nfs:
server: {{ Values.nfs.server }}
path: /ifs/kubernetes
mountOptions:
- vers=4
- minorversion=0
- rsize=1048576
- wsize=1048576
- hard
- timeo=600
- retrans=2
- noresvport

Then, check the StorageClass status.

1
2
3
4
$ kubectl get sc
kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-client cluster.local/nfs-client-provisioner Delete Immediate true 11h

Dynamically Provision PersistentVolume

Since v1.9. Users now can and should instead use the storageClassName field of the PersistentVolumeClaim object. The value of this field must match the name of a StorageClass configured by the administrator (see below).

To select the “fast” storage class, for example, a user would create the following PersistentVolumeClaim:

1
2
3
4
5
6
7
8
9
10
11
12
13
# nfs-client-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-nfs-server-provisioner-0
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs-client
resources:
requests:
storage: 1Gi

Check pvc.

1
2
3
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-nfs-server-provisioner-0 Bound pvc-34e125d0-5d24-4ae4-934d-6bf16b25ec2b 1Gi RWO nfs-client 4s

The following is a example about nfs-server-provisioner dynamically provision a PersistentVolume to the Deployment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: nfs-pvc
mountPath: "/usr/share/nginx/html"
volumes:
- name: nfs-pvc
persistentVolumeClaim:
claimName: data-nfs-server-provisioner-0

Apply nginx-deployment.yaml to create the Deployment.

1
$ kubectl apply -f nginx-deploymentyaml

Check Nginx Deployment.

1
2
3
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-64bf5ccdc8-mq26m 1/1 Running 0 13s

Then, the Pod of the Deployment will mount a Volume from nfs-client-provisioner.

rpcbind service not start

if the nfs packages is not install or rpcbind.service is not started, the Pod can not mount pv with error(such as
Unable to attach or mount volumes: unmounted volumes=[storage], unattached volumes=[config storage nginx-deployment-token-fr5t7]: timed out waiting for the condition) .

You need to install nfs packages, then start and enable rpcbind.service.

Uninstalling the Chart

To uninstall/delete the my-release deployment:

1
$ helm delete nfs-client-provisioner

The command removes all the Kubernetes components associated with the chart and deletes the release.

References

[1] NFS client provisioner - https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client

[2] Helm - https://helm.sh/

[3] Kubernetes - https://kubernetes.io/

[4] NFS Server and Client Installation on CentOS 7 - https://www.howtoforge.com/nfs-server-and-client-on-centos-7

[5] File Storage NAS: Reliable Network Attached Storage - Alibaba Cloud - https://www.alibabacloud.com/product/nas