Install Longhorn Rancher for Kubernetes Block Storage
Storage and specifically persistent storage has been a challenge with Kubernetes and containerized workloads. Rancher Longhorn is a solution that helps to solve the problem of Kubernetes persistent storage and allows organizations to install and configure Kubernetes storage easily and with a simple interface that takes the guesswork out of doing this. Let’s take a look at how to install Longhorn Rancher for Kubernetes block storage.
What is Longhorn from Rancher?
First, what is Longhorn? Longhorn is a solution, originally from Rancher, that provides a lightweight, reliable, and easy-to-use (a word you often don’t hear with Kubernetes) distributed block storage system for Kubernetes. The project is now developed as a project of the Cloud Native Computing Foundation.
Longhorn can be installed using the typical tools found with any Kubernetes cluster, including helm, kubectl, or using the Rancher UI. What can you do with Longhorn?
- Use Longhorn volumes as persistent storage in Kubernetes for backing distributed stateful applications
- Segment your block storage into Longhorn volumes to use Kubernetes with or without a cloud provider
- Replicate block storage across multiple nodes and, by extension, multiple locations/data centers for increased availability
- Backup your Kubernetes storage in an external storage location, such as NFS or AWS S3
- Create cross-cluster disaster recovery volumes. With this, you can have the data from a primary Kubernetes cluster quickly recovered from backup in a second Kubernetes cluster
- Schedule recurring snapshots of a volume. You can also schedule recurring backups to NFS or S3-compatible secondary storage
- Restore volumes from backup
- Perform lifecycle operations, such as upgrading Longhorn, without disrupting persistent volumes
Take a look at the architecture of Longhorn below to get a better understanding of the solution and how it allows mounting storage to your pods, and the replicas protecting data.
Installing Longhorn using Rancher
In Rancher, you click on the Kubernetes cluster you have managed using Rancher and navigate to Apps > Charts. You will see Longhorn listed.
When you click on Longhorn, you will then see the option to Install over at the top right-hand side.
Once you click to install Longhorn, it will launch a wizard of sorts to configure the Longhorn installation. First, choose the Kubernetes namespace you want to install Longhorn Rancher.
Next, you will see several configuration options you can update. Here, I am setting the Longhorn Storage class settings. I have changed the Storage Class Retain Policy to Retain. Also, you can define the replica count when you install Longhorn Rancher.
On the Services and Load Balancing configuration, you define how you want to expose the Longhorn service and dashboard. Here I am selecting NodePort and the port. Click Install.
The process to install Longhorn Rancher begins. You will see the command line environment open, showing the status of the installation in the Rancher UI.
After a minute or so, you can take a look at the Installed Apps and you will see Longhorn listed.
Browsing out to the configured NodePort, we see the Longhorn dashboard. As you can see below, there is no volume configured as of yet. However, we can see our storage that is schedulable and the nodes hosting the service.
If we navigate to Volume > Create Volume, we can begin the process to create a volume in Longhorn.
The Create Volume dialog box opens. Set the parameters of the volume, including size, and click OK.
Now that the volume has been created, click the Volume > Attach button. We now need to attach the volume to a Kubernetes host.
Select the host you want to attach the volume to.
The volume is created, attached, and healthy.
Now, if we revisit the dashboard, we can see we have the 1 volume listed along with the information we saw earlier.
If you go to your kubectl command line, you can issue the command:
kubectl get sc
This will check the default storage class in Kubernetes. As you can see, our default storage class is configured to Longhorn.
Install Longhorn Rancher FAQs
- What is Longhorn? Long horn is a lightweight, reliable, and easy-to-use distributed block storage system for Kubernetes that provides persistent block storage. It also provides an easy way to back up your Kubernetes data using an NFS or AWS S3 storage location. You can create cross-cluster disaster recovery volumes so that data from a primary Kubernetes cluster can be mounted in another cluster or recovered from backup.
- What is Rancher – Rancher is an open source solution that provides enterprise Kubernetes management. They have a healthy ecosystem of products and solutions that allow managing and maintaining your Kubernetes clusters and making difficult things, easy.
- What is a Kubernetes storage class? STorage classes in Kubernetes provides a way for administrators to describe the classes of storage they offer.
- What is Kubernetes? Kubernetes is an enterprise container orchestration platform that allows managing your containers in the way we have managed VMs for years now with availability and resource scheduling capabilities.
My rancher resources
- Rancher Node Template VMware ESXi – Ubuntu Cloud Image
- Rancher Desktop v1.0 Features Installation and Configuration
- Create Kubernetes Cluster with Rancher and VMware vSphere
- Rancher connect to existing cluster
- K3s Traefik Dashboard Enable and Configuration
Hopefully this quick and easy walkthrough on how to Install Longhorn Rancher for Kubernetes Block Storage has been helpful. There are many things I like about Longhorn. Specifically, it is super simple to setup and provides that point and click workflow to create storage in Kubernetes and perform backups of your data.