In this guide we will install the distributed block storage system Longhorn to a standard Origo OS Kubernetes cluster.
Install a Kubernetes cluster by following this guide.
NOTE: You can install as many nodes as you need instead of the default 2 (as shown in the image above). For convenience name your cluster “stabilekube” or something similar. If you need more storage than the standard 20GB per Kubernetes node, follow the instructions in this guide to expand the storage after installing the stack.
After the Kubernetes cluster is up and running, you must set a password for the stabile user in the “security” tab, and allow ssh access from your current IP address.
Once you have done this, head straight to your favourite ssh terminal and ssh to the stack administration server (running the control-plane), to execute all the commands in the steps below.
The administration server running the control plane is the one with a name ending in “.0” – find its IP address in the dashboard (as shown in the image above).
Before installing Longhorn we need to make iscsi and other tools available on each node in our Kubernetes cluster, since Longhorn depends on these. To this end we use the utility stabile-helper, which has a convenient command to execute a command on all nodes in a Stack (corresponding to each node in our Kubernetes cluster). From the ssh terminal on the administration server, as user stabile, type:
stabile-helper runcommand "apt-get update; apt-get install -y open-iscsi e2fsprogs xfsprogs lvm2"
Create directory for longhorn data and mount our data disks to this directory by typing the following commands:
stabile-helper runcommand "mkdir /var/lib/longhorn"
stabile-helper runcommand "echo '/dev/vdb1 /var/lib/longhorn ext4 noatime 0 0' >> /etc/fstab"
stabile-helper runcommand "mount /dev/vdb1 /var/lib/longhorn"
References:
https://longhorn.io/docs/1.2.2/deploy/install/install-with-kubectl/
https://longhorn.io/docs/1.2.2/deploy/accessing-the-ui/
https://longhorn.io/docs/1.2.2/deploy/accessing-the-ui/longhorn-ingress/
First retrieve the Longhorn yaml file:
wget https://raw.githubusercontent.com/longhorn/longhorn/v1.2.2/deploy/longhorn.yaml
Install Longhorn by applying the yaml file you just retrieved:
kubectl apply -f longhorn.yaml
Longhorn installs a lot of stuff on your cluster, so be prepared to wait a few minutes for it all to be up and running. Wait for all lights to turn green in your Kubernetes dashboard, or follow the progress by typing (and of course type ctrl-C to stop following):
kubectl get pods --namespace longhorn-system --watch
We will forward traffic through Apache to the Longhorn UI, using the same access control as for the Kubernetes dashboard in the Origo OS Kubernetes cluster.
First get the Longhorn front-end internal IP address and put it in a file:
kubectl get svc -n longhorn-system | sed -n -e 's/.*longhorn-frontend.*ClusterIP//p' | grep -oh "\S*" | grep -ohP "\d+\.\d+\.\d+\.\d+" | tee longhorn-frontend-ip
Then configure Apache for forward http and ws traffic to Longhorn:
sudo sed -i -e "s/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\/html\nProxyPass \/longhorn\/ http:\/\/`cat longhorn-frontend-ip`:80\/\nProxyPassReverse \/longhorn\/ http:\/\/`cat longhorn-frontend-ip`:80\//" /etc/apache2/sites-available/kubernetes-ssl.conf
sudo sed -i -e "s/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\/html\nRewriteEngine On\nRewriteCond %{HTTP:Upgrade} =websocket [NC]\nRewriteRule \/longhorn\/(.*) ws:\/\/`cat longhorn-frontend-ip`:80\/\$1 [P,L]/" /etc/apache2/sites-available/kubernetes-ssl.conf
sudo a2enmod rewrite proxy_wstunnel
sudo systemctl reload apache2
Now visit: https://ip-address-of-your-management-server:10002/longhorn/
and if needed log in with the same credentials you have set for the Kubernetes dashboard.
That’s it. You should now have a functioning Longhorn installation. The Longhorn storageclass should show up in your Kubernetes stack’s management UI, where you can set is as default.