Access the UI

Use kubectl --kubeconfig=kube_configxxx.yml -n longhorn-system get svc to get the external service IP for UI:

  1. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  2. longhorn-backend ClusterIP 10.20.248.250 <none> 9500/TCP 58m
  3. longhorn-frontend LoadBalancer 10.20.245.110 100.200.200.123 80:30697/TCP 58m

If the Kubernetes Cluster supports creating LoadBalancer, user can then use EXTERNAL-IP(100.200.200.123 in the case above) of longhorn-frontend to access the Longhorn UI. Otherwise the user can use <node_ip>:<port> (port is 30697in the case above) to access the UI.

Longhorn UI would connect to the Longhorn manager API, provides the overview of the system, the volume operations, and the snapshot/backup operations. It’s highly recommended for the user to check out Longhorn UI.

Noted that the current UI is unauthenticated at the moment.

Use Longhorn with Kubernetes

Longhorn provides the persistent volume directly to Kubernetes through one of the Longhorn drivers. No matter which driver you’re using, you can use Kubernetes StorageClass to provision your persistent volumes.

Use following command to create a default Longhorn StorageClass named longhorn.

  1. kubectl --kubeconfig=kube_configxxx.yml create -f https://raw.githubusercontent.com/rancher/longhorn/master/examples/storageclass.yml

Now you can create a pod using Longhorn like this:

  1. kubectl --kubeconfig=kube_configxxx.yml create -f https://raw.githubusercontent.com/rancher/longhorn/master/examples/pvc.yml

The yaml contains two parts:

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

More examples are available at ./examples/

Highlight features

Snapshot

A snapshot in Longhorn represents a volume state at a given time, stored in the same location of volume data on physical disk of the host. Snapshot creation is instant in Longhorn.

User can revert to any previous taken snapshot using the UI. Since Longhorn is a distributed block storage, please make sure the Longhorn volume is umounted from the host when revert to any previous snapshot, otherwise it will confuse the node filesystem and cause filesystem corruption.

Note about the block level snapshot

Longhorn is a crash-consistent block storage solution.

It’s normal for the OS to keep content in the cache before writing into the block layer. However, it also means if the all the replicas are down, then Longhorn may not contain the immediate change before the shutdown, since the content was kept in the OS level cache and hadn’t transfered to Longhorn system yet. It’s similar to if your desktop was down due to a power outage, after resuming the power, you may find some weird files in the hard drive.

To force the data being written to the block layer at any given moment, the user can run sync command on the node manually, or umount the disk. OS would write the content from the cache to the block layer in either situation.

Backup

A backup in Longhorn represents a volume state at a given time, stored in the secondary storage (backupstore in Longhorn word) which is outside of the Longhorn system. Backup creation will involving copying the data through the network, so it will take time.

A corresponding snapshot is needed for creating a backup. And user can choose to backup any snapshot previous created.

A backupstore is a NFS server or S3 compatible server.

A backup target represents a backupstore in Longhorn. The backup target can be set at Settings/General/BackupTarget

See here for details on how to setup backup target.

Recurring snapshot and backup

Longhorn supports recurring snapshot and backup for volumes. User only need to set when he/she wish to take the snapshot and/or backup, and how many snapshots/backups needs to be retains, then Longhorn will automatically create snapshot/backup for the user at that time, as long as the volume is attached to a node.

User can find the setting for the recurring snapshot and backup in the Volume Detail page.

Changing replica count of the volumes

The default replica count can be changed in the setting.

Also, when a volume is attached, the user can change the replica count for the volume in the UI.

Longhorn will always try to maintain at least given number of healthy replicas for each volume. If the current healthy replica count is less than specified replica count, Longhorn will start rebuilding new replicas. If the current healthy replica count is more than specified replica count, Longhorn will do nothing. In the later situation, if user delete one or more healthy replicas, or there are healthy replicas failed, as long as the total healthy replica count doesn’t dip below the specified replica count, Longhorn won’t start rebuilding new replicas.