A StorageClass provides a way for administrators to describe the "classes" of storage they offer. Different classes might map to quality-of-service levels, backup policies, or to arbitrary policies determined by the cluster administrators. Kubernetes itself is unopinionated about what classes represent. This concept is sometimes called "profiles" in other storage systems.
Notice: Please configure the following setting in the physical or virtual systems which contain NFS service.
For Ubuntu Linux:
sudo apt install -y nfs-common nfs-kernel-server
For RHEL 7/8:
sudo yum install nfs-utils
Add the provisioner and internal IP information to /etc/exports
Notice: The following code needs to be replaced with real-case information.
sudo vim /etc/exports
/provisioner <your_class_c_domain>/16(rw,no_root_squash,no_subtree_check)
/etc/exports
Create the folder to mount and store all files.
sudo mkdir -p /provisioner
Restart NFS service
sudo exportfs -a
# For Ubuntu
sudo systemctl restart nfs-kernel-server
# For RHEL
sudo systemctl status rpcbind
sudo systemctl restart nfs
sudo systemctl enable nfs
Notice: Please configure the following setting in other physical or virtual systems. You can use the ansible tool to set in the environment.
Create a file in any node which can mount via os level.
mkdir /tmp/testmount
sudo mount -t nfs 10.40.0.15:/provisioner /tmp/testmount/
echo -e "test123\\nline2" | sudo tee /tmp/testmount/test.txt
Check the file is in the NFS mounted folder.
cat /provisioner/test.txt
test123
line2
If you finish testing the file, you must need to umount the test mount point
sudo umount /tmp/testmount
Add the helm repo of nfs-subdir-external-provisioner
helm repo add nfs-subdir-external-provisioner <https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner>
helm repo update
Install provisioner by helm
helm install \\
nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \\
--create-namespace \\
--namespace nfs \\
--set nfs.server=<nfs-service-node-internal-ip> \\
--set nfs.path=<nfs-mount-path> \\
--set nfs.mountOptions='{nfsvers=4.1}' \\
--set storageClass.reclaimPolicy=Retain \\
--set storageClass.volumeBindingMode=Immediate
Example:
[Verify] the NFS Provisioner status in Kubernetes
Check nfs namespace has been created
kubectl get ns | grep nfs
nfs Active 54s
Check storage class nfs-client
has been created.
kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-client cluster.local/nfs-subdir-external-provisioner Retain Immediate true 3m52s
Make the NFS StorageClass as the default storage class
kubectl annotate sc nfs-client storageclass.kubernetes.io/is-default-class=true
kubectl get sc | grep default
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-client (default) cluster.local/nfs-subdir-external-provisioner Retain Immediate true 5m48s
[Verify] Test client storage can take mount point /provisioner
.
Create nfs-client-pvc pods
kubectl -n nfs apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: nfs-client-pvc
spec:
containers:
- command: ['/bin/sh', '-c']
args: ["sleep 999d"]
image: busybox
name: main
resources:
limits:
cpu: "50m"
memory: 128Mi
volumeMounts:
- name: data
mountPath: /**provisioner**
volumes:
- name: data
persistentVolumeClaim:
claimName: nfs-client-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-client-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: nfs-client
volumeMode: Filesystem
EOF
Check the nfs-client-pvc pod is running.
kubectl -n nfs get pod | grep nfs-client-pvc
nfs-client-pvc 1/1 Running 0 48s
Check the PVC which STATUS
column of PVC should Bound
.
kubectl -n nfs get pvc | grep nfs-client-pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nfs-client-pvc **Bound** pvc-8b64019d-6aed-4349-b8ba-5aaaede6a4ee 2Gi RWO nfs-client 6m27s
Execute onto pod shell in the master node which contains kubectl tool and create files in nfs-client-pvc
pods
kubectl -n nfs exec -it nfs-client-pvc -- sh
In nfs-client-pvc
pods, we will create the testing file which can be seen in nfs storage.
<pod> $ stat /provisioner/
File: /provisioner/
Size: 4096 Blocks: 8 IO Block: 32768 directory
<pod> $ echo "test123" | tee /provisioner/test.txt
test123
<pod> $ exit
Check the testing file in the /provisioner
folder in the NFS node.
cat /provisioner/test.txt
test123
line2
If you can get the file in the NFS node, you can delete the nfs-client-pvc
testing pod.
kubectl -n nfs delete pod nfs-client-pvc
pod "nfs-client-pvc" deleted