Since we announced Project Longhorn last year, there has been a great deal of interest in running Longhorn storage on a Kubernetes cluster.
Today, I am very excited to announce the availability of Project Longhorn v0.2, which is a persistent storage implementation for any Kubernetes cluster. Once deployed on a Kubernetes cluster, Longhorn automatically clusters all available local storage from all the nodes in the cluster to form replicated and distributed block storage. You can perform snapshot and backup operations on Longhorn volumes, and they will be synchronously replicated onto multiple nodes. We have ported Longhorn Manager to work as a Kubernetes controller. All Longhorn states are stored as Custom Resource Definitions (CRDs). There’s no need for a separate etcd server for Longhorn. Longhorn Manager exposes APIs to perform Longhorn volume operations and snapshot/backup operations, which would be used by the Longhorn UI and Kubernetes Flexvolume driver during the operation.
Run this one command to deploy the whole Longhorn storage system on your Kubernetes cluster.
kubectl create -f https://raw.githubusercontent.com/rancher/longhorn/v0.2/deploy/longhorn.yaml
(for GKE, see here) After deployment, you can use the UI by looking into Kubernetes services to find the proper IP:
kubectl -n longhorn-system get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE longhorn-backend ClusterIP 10.20.248.250 <none> 9500/TCP 58m longhorn-frontend LoadBalancer 10.20.245.110 126.96.36.199 80:12345/TCP 58m
So now you can access the UI using
<node_ip>:12345. Longhorn provides full integration with Kubernetes. You can create a pod with a volume backing by Longhorn like this.
apiVersion: v1 kind: Pod metadata: name: volume-test namespace: default spec: containers: - name: volume-test image: nginx:stable-alpine imagePullPolicy: IfNotPresent volumeMounts: - name: voll mountPath: /data ports: - containerPort: 80 volumes: - name: voll flexVolume: driver: "rancher.io/longhorn" fsType: "ext4" options: size: "2Gi" numberOfReplicas: "3" staleReplicaTimeout: "20" fromBackup: ""
Longhorn also supports dynamic provisioner. For example, you can define a StorageClass in Kubernetes like this:
kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: longhorn provisioner: rancher.io/longhorn parameters: numberOfReplicas: "3" staleReplicaTimeout: "30" fromBackup: ""
Then create a PVC and use it with a Pod:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: longhorn-volv-pvc spec: accessModes: - ReadWriteOnce storageClassName: longhorn resources: requests: storage: 2Gi --- 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
Want expert guidance on Longhorn? Sign up for a demo.
Longhorn is a 100% open-source project. To this day, it’s still a work in progress. We appreciate your comments as we continue to work on it!