Installing Longhorn with Helm¶
Now, let's enhance our homelab by installing Longhorn, a distributed block storage system for Kubernetes. Longhorn provides data persistence for our applications running in the cluster.
Prerequisites¶
Before we proceed, ensure you have the following in place:
- A functional Kubernetes cluster with K3s, including at least one master node and one or more worker nodes.
- Helm, the Kubernetes package manager, installed on your master node.
- SSH access to your master node.
apt-get install -y open-iscsi
to have open-iscsi available in every node
Add the Longhorn Helm Repository¶
I'll start by adding the Longhorn Helm chart repository to Helm. This repository hosts the Longhorn Helm chart, making it easy for us to install.
Now, Helm is aware of the Longhorn Helm chart.
Install Longhorn¶
Let's use Helm to install Longhorn:
This command installs Longhorn into the longhorn-system
namespace.
Verify Longhorn Installation¶
To confirm that Longhorn has been successfully installed and is up and running, we can use the following command:
This command should display the Longhorn pods within the longhorn-system
namespace, indicating that Longhorn is active and ready for use.
Access the Longhorn Dashboard¶
Longhorn provides a web-based dashboard for managing and monitoring persistent volumes. To access the dashboard, I'll create a Kubernetes service and use kubectl
port-forwarding to expose it:
kubectl -n longhorn-system get svc longhorn-frontend
kubectl port-forward svc/longhorn-frontend 8080:80
Now, I can access the Longhorn dashboard in a web browser by visiting http://localhost:8080
.
With Longhorn successfully installed, I have a reliable block storage system for my homelab Kubernetes cluster, enabling data persistence for my applications. The Longhorn dashboard makes it easy to manage and monitor persistent volumes.
LoadBalancer for Longhorn Dashboard¶
Create a LoadBalancer service without having to create a separate service manifest file. Here's how you can do it:
kubectl expose deployment longhorn-ui --namespace longhorn-system --name longhorn-dashboard --type=LoadBalancer --port=80 --target-port=80
This kubectl
command does the following:
- Exposes the deployment named
longhorn-ui
in thelonghorn-system
namespace. - Names the service as "longhorn-dashboard."
- Sets the service type to LoadBalancer.
- Specifies that the service should listen on port 80 and forward traffic to port 80 on the target.
The LoadBalancer service will be automatically provisioned, and you can obtain the external IP address assigned to it by using
Or using the alternative route: TLDR¶
Create a LoadBalancer Service Manifest:
Create a Kubernetes service manifest file, for example, longhorn-dashboard-service.yaml
, to define the LoadBalancer service. You can use a text editor to create and edit the file. Here's an example of the manifest:
apiVersion: v1
kind: Service
metadata:
name: longhorn-dashboard
namespace: longhorn-system
spec:
selector:
app: longhorn-ui
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
This manifest specifies a service named "longhorn-dashboard" in the longhorn-system
namespace. It selects pods with the label app: longhorn-ui
and exposes port 80. The service type is set to LoadBalancer.
Apply the Service Manifest:
Use kubectl
to apply the service manifest:
This command deploys the LoadBalancer service, and the cloud provider (if you're using one) will allocate an external IP for you to access the Longhorn dashboard.
Verify the Service:
To verify the service and get the external IP, you can use the following command:
Look for the "EXTERNAL-IP" field in the output. Once an external IP is assigned, you can access the Longhorn dashboard using that IP.
Now, you should be able to access the Longhorn dashboard using the external IP provided by the LoadBalancer service. This makes it more convenient to manage and monitor your Longhorn volumes in your homelab setup.
Upgrade Longhorn¶
Check release compatibility
First check upgrade compatibility on the longhorn release pages
Possibly upgrade longhorn version by version until you are on the desired version.
helm search repo longhorn -l
NAME CHART VERSION APP VERSION DESCRIPTION
longhorn/longhorn 1.8.1 v1.8.1 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.8.0 v1.8.0 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.7.3 v1.7.3 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.7.2 v1.7.2 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.7.1 v1.7.1 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.7.0 v1.7.0 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.6.4 v1.6.4 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.6.3 v1.6.3 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.6.2 v1.6.2 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.6.1 v1.6.1 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.6.0 v1.6.0 Longhorn is a distributed block storage system ...
longhorn/longhorn 1.5.5 v1.5.5 Longhorn is a distributed block storage system ...
After you have found the proper version to upgrade to:
Wait for all the new pods to have deployed successfully, this might take a few minutes.
Then go to the Longhorn UI and update all your volumes to use the new engine
- Navigate to volumes
- Sort or Engine Image upgradable == Yes
- Select all
Upgrade engine
in the dropdown menu- Select the newest engine you deployed and go!