Greetings folks,
This week it is time to get some storage working in our test cluster.
For this purpose I am choosing Longhorn but keep in mind there are a lot of other options to choose from. Longhorn comes from the same folks as K3S so it was a natural choice.
We can leverage a script to check our environment for Longhorn readiness:
https://github.com/longhorn/longhorn/blob/v1.6.2/scripts/environment_check.sh
No nfs-common so that is an easy one to fix on each node:
sudo apt update
sudo apt install nfs-common
Looking better now:
So let’s check the documentation and find out more about Multipathd:
https://ubuntu.com/server/docs/introduction-to-device-mapper-multipathing
I found some posts about editing the /etc/multipathd.conf file but I since this is a test system I decided to just disable it and see what happens:
sudo systemctl stop multipathd
sudo systemctl disable multipathd
Ran the script again and got the all clear:
We are going to use Helm for our install:
helm repo add longhorn https://charts.longhorn.io
helm repo update
Next we will install it:
helm install longhorn longhorn/longhorn --namespace longhorn-system --create-namespace --version 1.6.2
Give the installation some time to complete then check the pods:
k -n longhorn-system get po
In order to access the Longhorn UI we will need to add an ingress. Our setup has installed by default the powerful Traefik ingress controller so all we need to do is add an ingress to our Longhorn setup.
Create a file called longhorn-ing-traefik.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: longhorn-ingress
namespace: longhorn-system
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
traefik.ingress.kubernetes.io/router.middlewares: longhorn-system-svc-longhorn-headers@kubernetescrd
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: longhorn-frontend
port:
number: 80
Next we need to add some Middleware:
Create a file called treafik-middleware.yaml:
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: svc-longhorn-headers
namespace: longhorn-system
spec:
headers:
customRequestHeaders:
X-Forwarded-Proto: "https"
Now apply both:
k apply -f -n longhorn-system longhorn-ing-traefik.yaml traefik-middleware.yaml
Time to check the ingress:
k get ingress -n longhorn-system
Open your browser at that IP in the Address column (for me it is 192.168.0.235)
On the Node column you can add/edit/delete storage as you wish.
Time to test and see if this works:
Create an nginx pod manifest with a persistent volume claim. The pvc will ask the default storageclass to create a volume of persistent storage:
File name nginxpvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
namespace: nginx
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: task-pv-pod
namespace: nginx
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
Next create an nginx namespace and apply the manifest:
k create ns nginx
k apply -f nginxpvc.yaml
check that the pvc properly been bounded to the pv:
k get pvc -n nginx
Finally lets check the pod itself:
k get po -n nginx
For more detailed information on Longhorn and Traefik (the ingress and middleware sections I skimmed over here since they can go quite deep), checkout there documentation sites:
https://longhorn.io/docs/1.6.2/
https://doc.traefik.io/traefik/
Until next time when we bring Kasten into the equation.