Before you create Kubernetes volumes, you must first create a storage class. Use following command to create a StorageClass called longhorn.

    1. kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/examples/storageclass.yaml

    Now you can create a pod using Longhorn like this:

    1. kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/examples/pvc.yaml

    The above yaml file contains two parts:

    1. Create a PVC using Longhorn StorageClass.
    1. apiVersion: v1
    2. kind: PersistentVolumeClaim
    3. metadata:
    4. name: longhorn-volv-pvc
    5. spec:
    6. accessModes:
    7. - ReadWriteOnce
    8. storageClassName: longhorn
    9. resources:
    10. requests:
    11. storage: 2Gi
    1. Use it in the a Pod as a persistent volume:
    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: volume-test
    5. namespace: default
    6. spec:
    7. containers:
    8. - name: volume-test
    9. image: nginx:stable-alpine
    10. imagePullPolicy: IfNotPresent
    11. volumeMounts:
    12. - name: volv
    13. mountPath: /data
    14. ports:
    15. - containerPort: 80
    16. volumes:
    17. - name: volv
    18. persistentVolumeClaim:
    19. claimName: longhorn-volv-pvc

    More examples are available at ../examples/