Home Explore Blog CI



kubernetes

3rd chunk of `content/en/blog/_posts/2018-01-00-Introducing-Container-Storage-Interface.md`
ac5121041a4d6f28098536a44beeaa6971abb1c267f2c2d80000000100000d03
If the “fast-storage” StorageClass is marked default, there is no need to include the storageClassName in the PersistentVolumeClaim, it will be used by default.  


### Pre-Provisioned Volumes
You can always expose a pre-existing volume in Kubernetes by manually creating a PersistentVolume object to represent the existing volume. The following PersistentVolume, for example, exposes a volume with the name “existingVolumeName” belonging to a CSI storage plugin called “com.example.team/csi-driver”.  


```
apiVersion: v1

kind: PersistentVolume

metadata:

  name: my-manually-created-pv

spec:

  capacity:

    storage: 5Gi

  accessModes:

    - ReadWriteOnce

  persistentVolumeReclaimPolicy: Retain

  csi:

    driver: com.example.team/csi-driver

    volumeHandle: existingVolumeName

    readOnly: false
 ```



### Attaching and Mounting
You can reference a PersistentVolumeClaim that is bound to a CSI volume in any pod or pod template.  


```
kind: Pod

apiVersion: v1

metadata:

  name: my-pod

spec:

  containers:

    - name: my-frontend

      image: dockerfile/nginx

      volumeMounts:

      - mountPath: "/var/www/html"

        name: my-csi-volume

  volumes:

    - name: my-csi-volume

      persistentVolumeClaim:

        claimName: my-request-for-storage
 ```


When the pod referencing a CSI volume is scheduled, Kubernetes will trigger the appropriate operations against the external CSI plugin (ControllerPublishVolume, NodePublishVolume, etc.) to ensure the specified volume is attached, mounted, and ready to use by the containers in the pod.  

For more details please see the CSI implementation [design doc](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/container-storage-interface.md) and [documentation](https://github.com/kubernetes-csi/docs/wiki/Setup).  


### How do I create a CSI driver?
Kubernetes is as minimally prescriptive on the packaging and deployment of a CSI Volume Driver as possible. The minimum requirements for deploying a CSI Volume Driver on Kubernetes are documented [here](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/container-storage-interface.md#third-party-csi-volume-drivers).  

The minimum requirements document also contains a [section](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/container-storage-interface.md#recommended-mechanism-for-deploying-csi-drivers-on-kubernetes) outlining the suggested mechanism for deploying an arbitrary containerized CSI driver on Kubernetes. This mechanism can be used by a Storage Provider to simplify deployment of containerized CSI compatible volume drivers on Kubernetes.   

As part of this recommended deployment process, the Kubernetes team provides the following sidecar (helper) containers:  


- [external-attacher](https://github.com/kubernetes-csi/external-attacher)

  - Sidecar container that watches Kubernetes VolumeAttachment objects and triggers ControllerPublish and ControllerUnpublish operations against a CSI endpoint.
- [external-provisioner](https://github.com/kubernetes-csi/external-provisioner)

  - Sidecar container that watches Kubernetes PersistentVolumeClaim objects and triggers CreateVolume and DeleteVolume operations against a CSI endpoint.

Title: Using Pre-Provisioned CSI Volumes, Attaching/Mounting, and CSI Driver Creation
Summary
If a StorageClass is set as default, PersistentVolumeClaims don't need to specify it. Pre-existing volumes can be exposed in Kubernetes by creating a PersistentVolume object. To use a CSI volume, reference the PersistentVolumeClaim in a pod's volume definition. When the pod is scheduled, Kubernetes interacts with the CSI plugin to attach and mount the volume. Kubernetes offers minimal prescription on packaging and deploying CSI volume drivers, with minimum requirements documented. Sidecar containers like external-attacher and external-provisioner are available to assist in deploying containerized CSI drivers.