Skip to main content

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.

info

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.

  1. Navigate to the File Storage menu in the KakaoCloud console.

  2. 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.

    Image. Create file storage instance in the console Create a file storage instance

  3. After creating the file storage, check the mount information and VPC details on the instance details page for installing the NFS client provisioner.

    Image. Console file storage details page 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

  1. Enter the following command in the terminal to install the NFS client provisioner.

    Deployment command
    kubectl --kubeconfig=$KUBE_CONFIG apply -f https://raw.githubusercontent.com/kakaoicloud-guide/kubernetes-engine/main/guide-samples/NFSclientprovisioner/nfs-subdir-external-provisioner.yml
  2. After downloading the YAML file for configuring the deployment locally, input the corresponding information for File Storage IP and File 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]
  3. To execute the YAML file containing the File Storage IP and File 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.

  1. Before installing the NFS client provisioner, install the Helm client.

  2. Run the following command to add the official Helm chart repository.

    Command to add the official Helm chart repository
    helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
  3. After entering the File Storage IP and File Storage Mount Path information from the storage details page into the NFS client provisioner installation command, execute the command.

    NFS client provisioner installation command
    helm 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]
    ItemDescription
    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.

Command to verify StorageClass
kubectl --kubeconfig=$KUBE_CONFIG get sc
Result
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.

info

For more details on using PVC, refer to the Kubernetes official documentation.

Create PVC file
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).

Command to check PVC and PV
kubectl --kubeconfig=$KUBE_CONFIG get pvc // Check PVC 
kubectl --kubeconfig=$KUBE_CONFIG get pv // Check PV
Result
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