2020-02-14 18:45:18 +00:00
# Longhorn [](https://github.com/Ullaakut/astronomer)
2017-04-14 23:16:53 +00:00
2020-03-01 00:29:11 +00:00
### Build Status
2019-10-24 17:23:20 +00:00
* Engine: [](https://drone-publish.rancher.io/longhorn/longhorn-engine) [](https://goreportcard.com/report/github.com/rancher/longhorn-engine)
2020-03-01 00:29:11 +00:00
* Instance Manager: [](http://drone-publish.rancher.io/longhorn/longhorn-instance-manager)[](https://goreportcard.com/report/github.com/longhorn/longhorn-instance-manager)
2019-10-24 17:23:20 +00:00
* Manager: [](https://drone-publish.rancher.io/longhorn/longhorn-manager)[](https://goreportcard.com/report/github.com/rancher/longhorn-manager)
* UI: [](https://drone-publish.rancher.io/longhorn/longhorn-ui)
* Test: [](http://drone-publish.rancher.io/longhorn/longhorn-tests)
2020-03-01 00:29:11 +00:00
### Overview
2019-04-03 16:30:11 +00:00
Longhorn is a distributed block storage system for Kubernetes.
2017-04-16 07:25:39 +00:00
2019-04-03 16:30:11 +00:00
Longhorn is lightweight, reliable, and powerful. You can install Longhorn on an existing Kubernetes cluster with one `kubectl apply` command or using Helm charts. Once Longhorn is installed, it adds persistent volume support to the Kubernetes cluster.
2019-04-02 18:43:13 +00:00
2019-04-05 20:09:50 +00:00
Longhorn implements distributed block storage using containers and microservices. Longhorn creates a dedicated storage controller for each block device volume and synchronously replicates the volume across multiple replicas stored on multiple nodes. The storage controller and replicas are themselves orchestrated using Kubernetes. Here are some notable features of Longhorn:
2017-04-14 23:16:53 +00:00
2019-04-03 16:30:11 +00:00
1. Enterprise-grade distributed storage with no single point of failure
2. Incremental snapshot of block storage
3. Backup to secondary storage (NFS or S3-compatible object storage) built on efficient change block detection
2019-04-05 20:09:50 +00:00
4. Recurring snapshot and backup
2019-04-03 16:30:11 +00:00
5. Automated non-disruptive upgrade. You can upgrade the entire Longhorn software stack without disrupting running volumes!
6. Intuitive GUI dashboard
You can read more technical details of Longhorn [here ](http://rancher.com/microservices-block-storage/ ).
2017-04-21 07:17:27 +00:00
2018-08-23 22:08:22 +00:00
## Current status
2019-11-15 04:36:20 +00:00
Longhorn is beta-quality software. We appreciate your willingness to deploy Longhorn and provide feedback.
2018-08-23 22:08:22 +00:00
2020-03-11 01:58:12 +00:00
The latest release of Longhorn is **v0.8.0** .
2017-04-14 23:16:53 +00:00
2018-08-23 00:28:06 +00:00
## Source code
2017-04-27 20:15:23 +00:00
Longhorn is 100% open source software. Project source code is spread across a number of repos:
2017-04-27 20:12:32 +00:00
2019-07-22 18:27:29 +00:00
1. Longhorn engine -- Core controller/replica logic https://github.com/longhorn/longhorn-engine
1. Longhorn manager -- Longhorn orchestration, includes Flexvolume driver for Kubernetes https://github.com/longhorn/longhorn-manager
1. Longhorn UI -- Dashboard https://github.com/longhorn/longhorn-ui
2017-04-27 23:33:49 +00:00
2019-11-08 19:21:15 +00:00

2018-03-26 22:11:48 +00:00
2018-08-02 03:38:51 +00:00
# Requirements
2017-04-27 23:33:49 +00:00
2018-08-02 03:38:51 +00:00
1. Docker v1.13+
2019-11-15 22:07:25 +00:00
2. Kubernetes v1.14+.
2020-02-06 18:54:45 +00:00
3. `open-iscsi` has been installed on all the nodes of the Kubernetes cluster, and `iscsid` daemon is running on all the nodes.
2019-04-02 02:23:24 +00:00
1. For GKE, recommended Ubuntu as guest OS image since it contains open-iscsi already.
2. For Debian/Ubuntu, use `apt-get install open-iscsi` to install.
3. For RHEL/CentOS, use `yum install iscsi-initiator-utils` to install.
2020-03-04 22:09:40 +00:00
4. For EKS with `EKS Kubernetes Worker AMI with AmazonLinux2 image` ,
use `yum install iscsi-initiator-utils` to install. You may need to edit cluster security group to allow ssh access.
2019-09-30 08:56:27 +00:00
4. A host filesystem supports `file extents` feature on the nodes to store the data. Currently we support:
2019-09-15 21:39:54 +00:00
1. ext4
2. XFS
2017-04-27 23:33:49 +00:00
2019-04-02 02:23:24 +00:00
# Install
2018-09-14 00:47:44 +00:00
2019-04-03 16:30:11 +00:00
## On Kubernetes clusters Managed by Rancher 2.1 or newer
The easiest way to install Longhorn is to deploy Longhorn from Rancher Catalog.
2018-09-14 00:47:44 +00:00
2019-04-03 16:30:11 +00:00
1. On Rancher UI, select the cluster and project you want to install Longhorn. We recommended to create a new project e.g. `Storage` for Longhorn.
2. Navigate to the `Catalog Apps` screen. Select `Launch` , find Longhorn in the list. Select `View Details` , then click `Launch` . Longhorn will be installed in the `longhorn-system` namespace.
2019-09-21 21:54:13 +00:00
2019-04-02 18:43:13 +00:00
After Longhorn has been successfully installed, you can access the Longhorn UI by navigating to the `Catalog Apps` screen.
2019-04-03 16:30:11 +00:00
One benefit of installing Longhorn through Rancher catalog is Rancher provides authentication to Longhorn UI.
2018-09-14 00:47:44 +00:00
2019-04-03 16:30:11 +00:00
If there is a new version of Longhorn available, you will see an `Upgrade Available` sign on the `Catalog Apps` screen. You can click `Upgrade` button to upgrade Longhorn manager. See more about upgrade [here ](#upgrade ).
2018-09-14 00:47:44 +00:00
2019-04-03 16:30:11 +00:00
## On any Kubernetes cluster
2019-05-08 18:12:58 +00:00
### Install Longhorn with kubectl
2019-04-03 16:30:11 +00:00
You can install Longhorn on any Kubernetes cluster using following command:
2018-08-02 03:38:51 +00:00
2018-03-23 01:20:50 +00:00
```
2019-07-22 18:27:29 +00:00
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml
2018-03-23 01:20:50 +00:00
```
2019-04-03 16:30:11 +00:00
Google Kubernetes Engine (GKE) requires additional setup in order for Longhorn to function properly. If your are a GKE user, read [this page ](docs/gke.md ) before proceeding.
2017-04-14 23:16:53 +00:00
2019-05-08 18:12:58 +00:00
### Install Longhorn with Helm
First, you need to initialize Helm locally and [install Tiller into your Kubernetes cluster with RBAC ](https://helm.sh/docs/using_helm/#role-based-access-control ).
2019-05-09 03:57:59 +00:00
Then download Longhorn repository:
```
2019-07-22 18:27:29 +00:00
git clone https://github.com/longhorn/longhorn.git
2019-05-09 03:57:59 +00:00
```
Now using following command to install Longhorn:
2020-02-03 16:14:48 +00:00
* Helm2
2019-05-08 18:12:58 +00:00
```
2019-05-09 03:57:59 +00:00
helm install ./longhorn/chart --name longhorn --namespace longhorn-system
2019-05-08 18:12:58 +00:00
```
2020-02-03 16:14:48 +00:00
* Helm3
```
kubectl create namespace longhorn-system
helm install longhorn ./longhorn/chart/ --namespace longhorn-system
```
2019-05-08 18:12:58 +00:00
---
2019-04-02 02:30:53 +00:00
Longhorn will be installed in the namespace `longhorn-system`
2017-04-14 23:16:53 +00:00
2019-04-03 16:30:11 +00:00
One of the two available drivers (CSI and Flexvolume) would be chosen automatically based on the version of Kubernetes you use. See [here ](docs/driver.md ) for details.
2018-09-14 03:03:09 +00:00
2019-04-03 16:30:11 +00:00
A successful CSI-based deployment looks like this:
2017-12-06 02:37:00 +00:00
```
2018-01-16 01:16:18 +00:00
# kubectl -n longhorn-system get pod
2018-08-02 03:38:51 +00:00
NAME READY STATUS RESTARTS AGE
csi-attacher-0 1/1 Running 0 6h
csi-provisioner-0 1/1 Running 0 6h
engine-image-ei-57b85e25-8v65d 1/1 Running 0 7d
engine-image-ei-57b85e25-gjjs6 1/1 Running 0 7d
engine-image-ei-57b85e25-t2787 1/1 Running 0 7d
longhorn-csi-plugin-4cpk2 2/2 Running 0 6h
longhorn-csi-plugin-ll6mq 2/2 Running 0 6h
longhorn-csi-plugin-smlsh 2/2 Running 0 6h
longhorn-driver-deployer-7b5bdcccc8-fbncl 1/1 Running 0 6h
longhorn-manager-7x8x8 1/1 Running 0 6h
longhorn-manager-8kqf4 1/1 Running 0 6h
longhorn-manager-kln4h 1/1 Running 0 6h
longhorn-ui-f849dcd85-cgkgg 1/1 Running 0 5d
```
2017-12-06 02:37:00 +00:00
2019-04-02 02:26:55 +00:00
### Accessing the UI
2018-08-02 03:38:51 +00:00
2020-02-27 00:10:16 +00:00
> For Longhorn v0.8.0+, UI service type has been changed from `LoadBalancer` to `ClusterIP`
You can run `kubectl -n longhorn-system get svc` to get Longhorn UI service:
2017-04-14 23:16:53 +00:00
```
2017-12-06 02:37:00 +00:00
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
longhorn-backend ClusterIP 10.20.248.250 < none > 9500/TCP 58m
2020-02-27 00:10:16 +00:00
longhorn-frontend ClusterIP 10.20.245.110 < none > 80/TCP 58m
2018-08-02 03:38:51 +00:00
2017-04-14 23:16:53 +00:00
```
2020-02-27 00:10:16 +00:00
To access Longhorn UI when installed from YAML manifest, you need to create an ingress controller.
See more about how to create an Nginx ingress controller with basic authentication [here ](https://github.com/longhorn/longhorn/blob/master/docs/longhorn-ingress.md )
2018-03-26 17:52:41 +00:00
2019-04-02 02:23:24 +00:00
# Upgrade
2019-11-15 22:07:25 +00:00
[See here ](docs/upgrade.md ) for details.
2019-05-08 18:12:58 +00:00
## Upgrade Longhorn manager
##### On Kubernetes clusters Managed by Rancher 2.1 or newer
Follow [the same steps for installation ](#install ) to upgrade Longhorn manager
##### Using kubectl
2019-05-09 03:57:59 +00:00
```
2019-07-22 18:27:29 +00:00
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml
2019-05-09 03:57:59 +00:00
```
2019-05-08 18:12:58 +00:00
##### Using Helm
2019-05-09 03:57:59 +00:00
```
helm upgrade longhorn ./longhorn/chart
```
2019-05-08 18:12:58 +00:00
## Upgrade Longhorn engine
2019-11-15 22:07:25 +00:00
After Longhorn Manager was upgraded, Longhorn Engine also need to be upgraded using Longhorn UI. [See here ](docs/upgrade.md ) for details.
2017-12-06 02:37:00 +00:00
2019-09-21 21:54:13 +00:00
# Create Longhorn Volumes
2017-12-06 02:37:00 +00:00
2019-04-03 16:30:11 +00:00
Before you create Kubernetes volumes, you must first create a storage class. Use following command to create a StorageClass called `longhorn` .
2017-12-06 02:37:00 +00:00
```
2019-07-22 18:27:29 +00:00
kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/examples/storageclass.yaml
2017-12-06 02:37:00 +00:00
```
2018-08-04 07:31:04 +00:00
Now you can create a pod using Longhorn like this:
```
2019-07-22 18:27:29 +00:00
kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/examples/pvc.yaml
2018-08-04 07:31:04 +00:00
```
2019-04-03 16:30:11 +00:00
The above yaml file contains two parts:
2018-08-04 07:31:04 +00:00
1. Create a PVC using Longhorn StorageClass.
2017-04-14 23:16:53 +00:00
```
2017-12-06 02:37:00 +00:00
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: longhorn-volv-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 2Gi
2017-04-14 23:16:53 +00:00
```
2018-08-04 07:31:04 +00:00
2. Use it in the a Pod as a persistent volume:
2017-04-14 23:16:53 +00:00
```
2017-12-06 02:37:00 +00:00
apiVersion: v1
kind: Pod
metadata:
name: volume-test
namespace: default
spec:
containers:
- name: volume-test
2018-03-22 23:05:39 +00:00
image: nginx:stable-alpine
2017-12-06 02:37:00 +00:00
imagePullPolicy: IfNotPresent
volumeMounts:
- name: volv
mountPath: /data
ports:
- containerPort: 80
volumes:
- name: volv
persistentVolumeClaim:
claimName: longhorn-volv-pvc
2017-04-14 23:16:53 +00:00
```
2018-08-02 03:38:51 +00:00
More examples are available at `./examples/`
2019-04-03 16:30:11 +00:00
# Documentation
2019-04-02 02:23:24 +00:00
### [Snapshot and Backup](./docs/snapshot-backup.md)
### [Volume operations](./docs/volume.md)
2019-09-18 21:19:26 +00:00
### [Settings](./docs/settings.md)
### [Multiple disks](./docs/multidisk.md)
2018-08-23 00:28:06 +00:00
### [iSCSI](./docs/iscsi.md)
2019-05-16 21:20:35 +00:00
### [Kubernetes workload in Longhorn UI](./docs/k8s-workload.md)
2019-09-18 21:19:26 +00:00
### [Storage Tags](./docs/storage-tags.md)
### [Customized default setting](./docs/customized-default-setting.md)
### [Taint Toleration](./docs/taint-toleration.md)
2019-12-21 00:41:34 +00:00
### [Volume Expansion](./docs/expansion.md)
2017-04-14 23:16:53 +00:00
2018-09-14 03:03:09 +00:00
### [Restoring Stateful Set volumes](./docs/restore_statefulset.md)
2018-08-22 19:36:59 +00:00
### [Google Kubernetes Engine](./docs/gke.md)
2019-02-22 01:00:28 +00:00
### [Deal with Kubernetes node failure](./docs/node-failure.md)
2019-03-26 21:09:59 +00:00
### [Use CSI driver on RancherOS/CoreOS + RKE or K3S](./docs/csi-config.md)
2019-03-23 01:31:52 +00:00
### [Restore a backup to an image file](./docs/restore-to-file.md)
2019-05-17 18:15:03 +00:00
### [Disaster Recovery Volume](./docs/dr-volume.md)
2019-11-13 07:36:07 +00:00
### [Recover volume after unexpected detachment](./docs/recover-volume.md)
2018-09-14 03:03:09 +00:00
2019-04-03 16:30:11 +00:00
# Troubleshooting
2019-02-22 19:41:56 +00:00
You can click `Generate Support Bundle` link at the bottom of the UI to download a zip file contains Longhorn related configuration and logs.
2019-02-22 01:00:28 +00:00
2018-09-14 03:03:09 +00:00
See [here ](./docs/troubleshooting.md ) for the troubleshooting guide.
2018-08-22 19:36:59 +00:00
2019-04-03 16:30:11 +00:00
# Uninstall Longhorn
2018-08-02 03:38:51 +00:00
2019-05-08 18:12:58 +00:00
### Using kubectl
2019-04-02 18:43:13 +00:00
1. To prevent damaging the Kubernetes cluster, we recommend deleting all Kubernetes workloads using Longhorn volumes (PersistentVolume, PersistentVolumeClaim, StorageClass, Deployment, StatefulSet, DaemonSet, etc) first.
2017-04-14 23:16:53 +00:00
2019-04-02 18:43:13 +00:00
2. Create the uninstallation job to clean up CRDs from the system and wait for success:
2019-01-11 19:08:02 +00:00
```
2019-07-22 18:27:29 +00:00
kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/uninstall/uninstall.yaml
2019-04-18 01:56:07 +00:00
kubectl get job/longhorn-uninstall -w
2019-01-11 19:08:02 +00:00
```
2018-03-23 01:20:50 +00:00
2019-01-11 19:08:02 +00:00
Example output:
2017-04-14 23:16:53 +00:00
```
2019-07-22 18:27:29 +00:00
$ kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/uninstall/uninstall.yaml
2019-04-18 01:56:07 +00:00
serviceaccount/longhorn-uninstall-service-account created
clusterrole.rbac.authorization.k8s.io/longhorn-uninstall-role created
clusterrolebinding.rbac.authorization.k8s.io/longhorn-uninstall-bind created
2019-01-11 19:08:02 +00:00
job.batch/longhorn-uninstall created
2019-04-18 01:56:07 +00:00
$ kubectl get job/longhorn-uninstall -w
NAME COMPLETIONS DURATION AGE
longhorn-uninstall 0/1 3s 3s
longhorn-uninstall 1/1 20s 20s
2019-01-11 19:08:02 +00:00
^C
2017-12-06 02:37:00 +00:00
```
2017-04-16 07:25:39 +00:00
2019-01-11 19:08:02 +00:00
3. Remove remaining components:
```
2019-07-22 18:27:29 +00:00
kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml
kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/master/uninstall/uninstall.yaml
2019-01-11 19:08:02 +00:00
```
2019-04-18 01:56:07 +00:00
2019-07-22 18:27:29 +00:00
Tip: If you try `kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml` first and get stuck there,
pressing `Ctrl C` then running `kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/uninstall/uninstall.yaml` can also help you remove Longhorn. Finally, don't forget to cleanup remaining components.
2018-03-23 01:20:50 +00:00
2019-05-08 18:12:58 +00:00
### Using Helm
```
helm delete longhorn --purge
```
2018-03-23 01:20:50 +00:00
2019-08-20 19:30:02 +00:00
## Community
Longhorn is an open source software, so contribution are greatly welcome. Please read [Code of Conduct ](./CODE_OF_CONDUCT.md ) and [Contributing Guideline ](./CONTRIBUTING.md ) before contributing.
2019-10-23 18:59:30 +00:00
Contributing code is not the only way of contributing. We value feedbacks very much and many of the Longhorn features are originated from users' feedback. If you have any feedbacks, feel free to [file an issue ](https://github.com/longhorn/longhorn/issues/new?title=*Summarize%20your%20issue%20here*&body=*Describe%20your%20issue%20here*%0A%0A---%0AVersion%3A%20`` ) and talk to the developers at the [CNCF ](https://slack.cncf.io/ ) [#longhorn ](https://cloud-native.slack.com/messages/longhorn ) slack channel.
2019-08-20 19:30:02 +00:00
2017-04-16 07:25:39 +00:00
## License
2020-03-01 00:29:11 +00:00
Copyright (c) 2014-2020 The Longhorn Authors
2018-08-02 03:38:51 +00:00
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
2017-04-16 07:25:39 +00:00
[http://www.apache.org/licenses/LICENSE-2.0 ](http://www.apache.org/licenses/LICENSE-2.0 )
2018-08-02 03:38:51 +00:00
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
2019-11-08 19:10:35 +00:00
### Longhorn is a [CNCF Sandbox Project](https://www.cncf.io/sandbox-projects/)
