Introduction
Longhorn is a cloud-native distributed block storage solution for Kubernetes. It enables persistent storage for Kubernetes applications with built-in replication, backup, and recovery features. Unlike traditional storage solutions, Longhorn provides lightweight, highly-available storage with automatic failover and data redundancy. It is especially useful for stateless workloads requiring reliable persistent storage in Kubernetes.
In this guide, we’ll configure Longhorn on an existing Kubernetes cluster with one master node and two worker nodes running Debian 12. We’ll also expose the Longhorn UI for easier management. Since we assume MetalLB is already deployed, we will leverage it for LoadBalancer service exposure.
Prerequisites
Before proceeding, ensure the following:
- A running Kubernetes cluster with one master node and two worker nodes
kubectl
installed on your local machine- Helm installed on the master node
- SSH access to all nodes
open-iscsi
installed on all nodes (required for Longhorn to function properly)- MetalLB already deployed for LoadBalancer service exposure
Install open-iscsi
on all nodes
Run the following command on each node:
sudo apt update && sudo apt install -y open-iscsi
sudo systemctl enable --now iscsid
Verify that the iscsid
service is running:
systemctl status iscsid
Procedure
Step 1: Deploy Longhorn
Add the Helm Repository
helm repo add longhorn https://charts.longhorn.io
helm repo update
Install Longhorn
kubectl create namespace longhorn-system
helm install longhorn longhorn/longhorn --namespace longhorn-system
Step 2: Verify Longhorn Installation
Check if all Longhorn components are running:
kubectl get pods -n longhorn-system
Ensure all pods are in a Running
state before proceeding.
Step 3: Expose Longhorn UI
Since MetalLB is deployed, we will expose the Longhorn UI via a LoadBalancer
service:
kubectl patch svc longhorn-frontend -n longhorn-system -p '{"spec": {"type": "LoadBalancer"}}'
Get the assigned external IP:
kubectl get svc longhorn-frontend -n longhorn-system
Access the UI using http://<load-balancer-ip>
.
Step 4: Configure Longhorn
- Navigate to the Longhorn UI.
- Set up the default storage class.
- Configure backup settings if needed.
- Attach volumes to workloads as necessary.
Troubleshooting
Issue: Longhorn Pods Not Running on a New Worker Node
If longhorn-csi-plugin
and longhorn-manager
pods on the new worker node are not running, there is a high chance that the cluster DNS service is not functioning properly. To resolve this issue, restart the coredns
service:
kubectl -n kube-system rollout restart deployment coredns
Wait a few moments and check if the Longhorn pods on the new worker node start running:
kubectl get pods -n longhorn-system -o wide
If the issue persists, check the logs of the affected pods for further debugging:
kubectl logs -n longhorn-system <pod-name>
Conclusion
We have successfully installed Longhorn on an existing Kubernetes cluster running Debian 12. Longhorn provides high availability, data replication, and snapshots, making it an excellent choice for cloud-native workloads. By leveraging MetalLB, we have exposed the Longhorn UI using a LoadBalancer service, making it easily accessible. You can now explore its features, including backup and restore, volume management, and monitoring, through its UI.
Leave a Reply