Create Longhorn Volumes

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

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

Now you can create a pod using Longhorn like this:

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.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: longhorn-volv-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 2Gi
  1. Use it in the a Pod as a persistent volume:
apiVersion: v1
kind: Pod
metadata:
  name: volume-test
  namespace: default
spec:
  containers:
  - name: volume-test
    image: nginx:stable-alpine
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: volv
      mountPath: /data
    ports:
    - containerPort: 80
  volumes:
  - name: volv
    persistentVolumeClaim:
      claimName: longhorn-volv-pvc

More examples are available at ../examples/