Configure NFS client provisioner
To use persistent volumes in a cluster, you typically need to configure both storage and the PersistentVolume object directly. In Kubernetes Engine, you can use the NFS client provisioner to utilize KakaoCloud File Storage as persistent volumes. Once the NFS client provisioner is installed in the cluster, you can easily create persistent volumes by creating a PersistentVolumeClaim.
The steps to configure the NFS client provisioner are as follows.
Step 1. Complete prerequisites
Before setting up the NFS client provisioner, the following prerequisites must be completed. This process is done only once per cluster.
Configure kubectl control
Before proceeding with deployment, set up kubectl control for the cluster.
If kubectl control is not configured, refer to kubectl control configuration for setup instructions.
Create file storage
Create file storage for your Kubernetes Engine cluster.
-
Navigate to the File Storage menu in the KakaoCloud console.
-
On the Instance tab, click the [Create instance] button.
- When creating the instance, ensure the VPC for file storage matches the VPC of the cluster where NFS is to be applied.
- To allow access from the nodes of the Kubernetes Engine cluster, set the Access Control option to Allow access from all private IPs within the specified VPC.
Create a file storage instance
-
After creating the file storage, check the mount information and VPC details on the instance details page for installing the NFS client provisioner.
Console file storage details page
Step 2. Configure NFS client provisioner
Install the NFS client provisioner to dynamically use the previously created file storage as a persistent volume through a PVC (PersistentVolumeClaim). You can install the NFS client provisioner using either a YAML file or Helm.
Deploy NFS client provisioner with a YAML file
-
Enter the following command in the terminal to install the NFS client provisioner.
Deployment commandkubectl --kubeconfig=$KUBE_CONFIG apply -f https://raw.githubusercontent.com/kakaoicloud-guide/kubernetes-engine/main/guide-samples/NFSclientprovisioner/nfs-subdir-external-provisioner.yml
-
After downloading the YAML file for configuring the deployment locally, input the corresponding information for
File Storage IP
andFile Storage Mount Path
from the storage details page into spec > template > spec > containers > env and spec > template > spec > volumes sections in the deployment file, then save the file.Check deployment configuration YAML spec# Source: nfs-subdir-external-provisioner/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-subdir-external-provisioner
labels:
chart: nfs-subdir-external-provisioner-4.0.18
heritage: Helm
app: nfs-subdir-external-provisioner
release: nfs-subdir-external-provisioner
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-subdir-external-provisioner
release: nfs-subdir-external-provisioner
template:
metadata:
annotations:
labels:
app: nfs-subdir-external-provisioner
release: nfs-subdir-external-provisioner
spec:
serviceAccountName: nfs-subdir-external-provisioner
securityContext:
{}
containers:
- name: nfs-subdir-external-provisioner
image: "registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2"
imagePullPolicy: IfNotPresent
securityContext:
{}
volumeMounts:
- name: nfs-subdir-external-provisioner-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: cluster.local/nfs-subdir-external-provisioner
- name: NFS_SERVER
value: [File Storage IP]
- name: NFS_PATH
value: [File Storage Mount Path]
volumes:
- name: nfs-subdir-external-provisioner-root
nfs:
server: [File Storage IP]
path: [File Storage Mount Path] -
To execute the YAML file containing the
File Storage IP
andFile Storage Mount Path
information entered in the previous step, run the following command.-
When applying the YAML file, ensure you use the actual filename of the YAML file saved locally.
kubectl --kubeconfig=$KUBE_CONFIG apply -f {YAML 파일명}.yaml
-
Deploy NFS client provisioner using Helm
Install the NFS client provisioner using Helm, the Kubernetes package management tool.
-
Before installing the NFS client provisioner, install the Helm client.
- For detailed instructions on installing Helm for different operating systems, refer to the Helm official documentation > Installing Helm.
-
Run the following command to add the official Helm chart repository.
Command to add the official Helm chart repositoryhelm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
-
After entering the
File Storage IP
andFile Storage Mount Path
information from the storage details page into the NFS client provisioner installation command, execute the command.NFS client provisioner installation commandhelm install --kubeconfig=$KUBE_CONFIG nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner --set nfs.server=[File Storage IP] --set nfs.path=[File Storage Mount Path]
Item Description File Storage IP ‘Network’ of the file storage File Storage Mount Path ‘Mount information’ of the file storage
Step 3. Verify StorageClass and test automatic provisioning
Verify StorageClass
After installing the NFS client provisioner, run the following command to verify the StorageClass.
kubectl --kubeconfig=$KUBE_CONFIG get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-client cluster.local/nfs-subdir-external-provisioner Delete Immediate true 12m
Create PersistentVolumeClaim and test automatic provisioning
Create a PVC (PersistentVolumeClaim) to test automatic provisioning. When deploying a pod to use the PVC, declare the PVC in the pod configuration, and set the pod to use the PVC. This will dynamically create the file storage volume and the PV (PersistentVolume) object.
For more details on using PVC, refer to the Kubernetes official documentation.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-claim
spec:
storageClassName: nfs-client
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Mi
Step 4. Allocate file storage
After completing the NFS client provisioner installation, verify the file storage to be used as a persistent volume. Run the following command to check the PVC (PersistentVolumeClaim) and PV (PersistentVolume).
kubectl --kubeconfig=$KUBE_CONFIG get pvc // Check PVC
kubectl --kubeconfig=$KUBE_CONFIG get pv // Check PV
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
test-claim Bound pvc-4724b46a-557d-46f9-97a9-dc94225c2d49 1Mi RWX nfs-client 13h
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-4724b46a-557d-46f9-97a9-dc94225c2d49 1Mi RWX Delete Bound default/test-claim nfs-client 13h