NFS CSI Driver

repository·master·Indexed 23 days ago

https://github.com/kubernetes-csi/csi-driver-nfs

The NFS CSI Driver enables Kubernetes to interface with NFSv3 and NFSv4 servers, supporting both static and dynamic volume provisioning via subdirectories. It provides features such as volume cloning (v4.3.0+), high-availability controller configurations, and fsGroupPolicy support for Kubernetes 1.20+ clusters. The driver can be installed and customized using Helm 3, allowing for multiple storage classes and custom driver identities.

Tokens
30.7K
Snippets
61
Records
89
Agent score
79%

What's inside csi-driver-nfs

  1. Overview of the NFS CSI Driver for Kubernetes

    master

    The NFS CSI Driver allows Kubernetes clusters to access existing NFSv3 or NFSv4 servers. It supports dynamic provisioning of Persistent Volumes (PVs) via Persistent Volume Claims (PVCs) by automatically creating new subdirectories on the configured NFS server.

    Key Details:

    • CSI plugin name: nfs.csi.k8s.io
    • Project Status: GA (General Availability)
    • Prerequisite: An existing and already configured NFSv3 or NFSv4 server.
  2. Configure High-Availability for the NFS CSI Controller

    master

    To run multiple controller replicas (controller.replicas > 1), you must ensure that replicas do not co-locate on the same node. This is because the controller uses hostNetwork: true and its liveness-probe sidecar binds to a fixed host port (controller.livenessProbe.healthPort, default 29652). If two pods attempt to run on the same node, the second pod's sidecar will fail to bind the port, causing a CrashLoopBackOff.

    Requirements for HA:

    1. The cluster must have at least as many schedulable nodes as controller.replicas.
    2. You must apply podAntiAffinity using the kubernetes.io/hostname topology key to prevent co-location.

    Note: If you see leader-election log lines like "Failed to update lease optimistically, falling back to slow path" in the active controller, this is normal behavior when multiple candidates are racing for the same lease and does not indicate a bug.

    Single-node clusters: For development clusters like k3d or kind, you must keep controller.replicas=1.

    controller:
      replicas: 2
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - topologyKey: kubernetes.io/hostname
              labelSelector:
                matchLabels:
                  app: csi-nfs-controller
  3. Verify NFS CSI driver pod status

    master

    After installation, verify that the controller and node pods are running in the kube-system namespace using the following commands:

    kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-node

    Successful pods should show a Running status with all containers (e.g., 4/4 for controller, 3/3 for node) being READY.

    kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-node
  4. Install NFS CSI driver v4.13.1 using kubectl

    master

    You can install the NFS CSI driver on a Kubernetes cluster using one of two methods: a remote installation via a shell script or a local installation from a cloned repository.

    Remote Install

    Use curl to fetch and execute the installation script directly from GitHub.

    Local Install

    Clone the repository, navigate to the directory, and run the installation script locally.

    Verify Installation

    After running the installation, verify that the controller and node pods are running by checking their status in the kube-system namespace.

    # Remote install
    curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.13.1/deploy/install-driver.sh | bash -s v4.13.1 --
    
    # Local install
    git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
    cd csi-driver-nfs
    ./deploy/install-driver.sh v4.13.1 local
    
    # Check pods status
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-node
  5. Build the NFS CSI driver

    master

    To build the project from source, clone the repository into your $GOPATH/src/sigs.k8s.io/ directory and use make to compile the driver. Before submitting code, run make verify to execute verification tests.

    If you modify configuration files within the charts directory, you must update the Helm chart package using the following command:

  6. Use Dynamic Provisioning with a StorageClass

    master

    To use the NFS CSI Driver for dynamic provisioning, create a StorageClass with the nfs.csi.k8s.io provisioner. You must specify the server (NFS server address) and share (NFS export path) in the parameters section.

    Note: If you need to provide mountOptions for the DeleteVolume operation, you must also include a provisioner secret using the following keys:

    • csi.storage.k8s.io/provisioner-secret-name
    • csi.storage.k8s.io/provisioner-secret-namespace
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: nfs-csi
    provisioner: nfs.csi.k8s.io
    parameters:
      server: nfs-server.default.svc.cluster.local
      share: /
      # csi.storage.k8s.io/provisioner-secret is only needed for providing mountOptions in DeleteVolume
      # csi.storage.k8s.io/provisioner-secret-name: "mount-options"
      # csi.storage.k8s.io/provisioner-secret-namespace: "default"
    reclaimPolicy: Delete
    volumeBindingMode: Immediate
    allowVolumeExpansion: true
    mountOptions:
      - nfsvers=4.1
  7. Install NFS CSI driver v4.12.0 using kubectl

    master

    You can install the NFS CSI driver on a Kubernetes cluster using kubectl via two methods: a remote installation using a shell script from GitHub, or a local installation using a cloned repository.

    Remote Install

    Use curl to fetch and execute the installation script directly from the repository.

    Local Install

    Clone the repository, navigate to the directory, and run the installation script locally.

    Verify Installation

    After installation, verify that the controller and node pods are running in the kube-system namespace using the following commands:

    # Remote install
    curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.12.0/deploy/install-driver.sh | bash -s v4.12.0 --
    
    # Local install
    git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
    cd csi-driver-nfs
    ./deploy/install-driver.sh v4.12.0 local
    
    # Check pods status
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-node
  8. Uninstall NFS CSI driver v4.2.0

    master

    To remove the NFS CSI driver version 4.2.0 from your cluster, use either the remote uninstall script or the local uninstall script.

    Remote Uninstall

    Execute the uninstall script directly from GitHub using curl.

    Local Uninstall

    Clone the repository, check out the specific version v4.2.0, and run the local uninstall script.

    # Remote uninstall
    curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.2.0/deploy/uninstall-driver.sh | bash -s v4.2.0 --
    
    # Local uninstall
    git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
    cd csi-driver-nfs
    git checkout v4.2.0
    ./deploy/uninstall-driver.sh v4.2.0 local
  9. Install NFS CSI driver v4.13.4 using kubectl

    master

    You can install the NFS CSI driver v4.13.4 on your Kubernetes cluster using two methods: a remote installation via a shell script or a local installation from the repository source.

    Remote Install

    Use curl to fetch and execute the installation script directly from GitHub.

    Local Install

    Clone the repository, navigate to the directory, and run the installation script locally.

    After installation, verify the status of the controller and node pods to ensure they are running.

    # Option#1. remote install
    curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.13.4/deploy/install-driver.sh | bash -s v4.13.4 --
    
    # Option#2. local install
    git clone https://github.com/kubernetes-csi/csi-driver-nfs.git
    cd csi-driver-nfs
    ./deploy/install-driver.sh v4.13.4 local
    
    # check pods status
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller
    kubectl -n kube-system get pod -o wide -l app=csi-nfs-node