Container Storage Interface (CSI)

Container Storage Interface (CSI) is now available as Beta in Kubernetes v1.10. With the promotion to Beta, CSI is now enabled by default. For more information about CSI Beta implementation in Kubernetes, see Container Storage Interface (CSI) for Kubernetes Goes Beta Opens in a new tab.

Configuring CSI

Most CSI plug-ins require that the --allow-privileged=true flag is set on the API server binary and kubelet binaries. This flag is enabled by default in IBM Cloud Private. For an IBM Cloud Private environment, you can use CSI Volume in a Kubernetes pod without having to set any extra configuration.

Example: Deploying a CSI NFS driver in IBM Cloud Private

Sample files used in this sample deployment are available from the Kubernetes GitHub repository. See kubernetes-csi/drivers Opens in a new tab.

  1. Install NFS. For more information about setting up NFS, see the Prerequisites section in the Creating an NFS PersistentVolume topic.
  2. Clone the kubernetes-csi/drivers Opens in a new tab repository.

  3. Switch to the nfs directory.

    cd drivers/pkg/nfs
    
  4. Create the deployment.

     kubectl create -f ./deploy/kubernetes/
    

    The output resembles the following code:

     service "csi-attacher-nfsplugin" created
     statefulset.apps "csi-attacher-nfsplugin" created
     serviceaccount "csi-attacher" created
     clusterrole.rbac.authorization.k8s.io "external-attacher-runner" created
     clusterrolebinding.rbac.authorization.k8s.io "csi-attacher-role" created
     daemonset.apps "csi-nodeplugin-nfsplugin" created
     serviceaccount "csi-nodeplugin" created
     clusterrole.rbac.authorization.k8s.io "csi-nodeplugin" created
     clusterrolebinding.rbac.authorization.k8s.io "csi-nodeplugin" created
    
  5. Deploy a pod by using the created CSI volume.

    1. Locate the NFS server.

       showmount -e
      

      The output resembles the following code:

       Export list for nfsserver:
       /nfs *
      
    2. Edit the examples/kubernetes/nginx.yaml file. Update the server and share parameters to match your system settings.

       cat examples/kubernetes/nginx.yaml | grep csi -A 5
      

      The output resembles the following code:

         csi:
           driver: csi-nfsplugin
           volumeHandle: data-id
           volumeAttributes:
             server: 10.10.25.7
             share: /nfs
       ---
      
    3. Create a pod using the NFS driver.

       kubectl create -f examples/kubernetes/nginx.yaml
      

      The output resembles the following code:

       persistentvolume "data-nfsplugin" created
       persistentvolumeclaim "data-nfsplugin" created
       pod "nginx" created
      
  6. Check the mount point.

    1. Access the nginx container.

       kubectl exec -it nginx sh
      
    2. Change to the /var/www directory.

       cd /var/www
      
    3. Create a file.

       touch test
      
    4. List the file on the mount point.

      ls
      

      The output resembles the following code:

      test
      
  7. Check the NFS server.

    1. Find the server.

      hostname
      

      The output resembles the following code:

      nfsserver
      
    2. List the files on the server.

      ls /nfs
      

      The output resembles the following code:

      test