Aller au contenu

Longhorn

Introduction

Longhorn est un logiciel de stockage persistant pour les clusters Kubernetes

Installation

Vérification des pré-requis

sudo dnf -y install jq
curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v1.8.2/scripts/environment_check.sh | bash

Note

Si les prérequis ne sont pas remplis exécutez les commandes ci-dessous:
sudo systemctl enable iscsid
sudo systemctl start iscsid
sudo modprobe iscsi_tcp

Fichier valeurs

cd /tmp
curl https://gmodocs.dyndns.org/files/longhorn-1.0.3.tar.gz -o longhorn-1.0.3.tar.gz
tar zxvf longhorn-1.0.3.tar.gz
cd longhorn

Secret S3

La connection au serveur S3 nécessite un nom d'utilisateur (awsAccessKey), un mot de passe (awsSecretAccessKey) et un serveur S3 (awsEndpoint). Ces données doivent être en base64

echo -n "longhorn-backups-user" | base64
bG9uZ2hvcm4tYmFja3Vwcy11c2Vy

echo -n "userPasswordAChanger" | base64
awsSecretAccessKey: dXNlclBhc3N3b3JkQUNoYW5nZXI=

echo -n "http://172.31.10.13:9000" | base64
awsEndpoint: aHR0cDovLzE3Mi4zMS4xMC4xMzo5MDAw

Note

La valeur des clés awsSecretAccessKey (utilisateur) et awsSecretAccessKey (mot de passe) doit correspondre à ce qui a été saisi lors de la création de l'utilisateur et la valeur awsEndpoint doit correspondre à l'adresse IP de votre serveur S3

vim longhornbackups/longhorn-secret-values.yaml
data:
  # echo -n "longhorn-backups-user" | base64
  awsAccessKey: bG9uZ2hvcm4tYmFja3Vwcy11c2Vy
  # echo -n "userPasswordAChanger" | base64  
  awsSecretAccessKey: dXNlclBhc3N3b3JkQUNoYW5nZXI=
  # echo -n "http://<adresse_ip_du_serveur_sr>:9000" | base64 
  # dans cet exemple http://172.31.10.13:9000 
  awsEndpoint: aHR0cDovLzE3Mi4zMS4xMC4xMzo5MDAw

Installation du secret

helm upgrade minio-sos-secret ./longhornbackups \
--install \
--atomic \
--cleanup-on-fail \
--values=./longhornbackups/longhorn-secret-values.yaml \
--namespace longhorn-system \
--create-namespace

Vérification

kubectl get secret -n longhorn-system

Installation de longhorn

Il faut installer une version stable (1.11.2)

Ajouter le repo helm de longhorn

helm repo add longhorn https://charts.longhorn.io
helm repo update
helm search repo longhorn --versions

Installer longhorn

helm upgrade longhorn longhorn/longhorn \
--install \
--atomic \
--cleanup-on-fail \
--version 1.11.2 \
--values=longhorn-values.yaml \
--namespace longhorn-system \
--create-namespace

Note

L'installation prend du temps. Soyez patient !

Vérfication

Attendre que tous les pods soient Running

kubectl get pods -n longhorn-system

Configuration du dashboard longhorn

Entrée DNS

Dans cet exemple l'url du dashboard est longhorn.gmolab.net. Récupérer l'adresse IP public (EXTERNAL-IP)

kubectl get svc -n traefik-system
NAME             TYPE           CLUSTER-IP      --> EXTERNAL-IP <--    PORT(S)                      AGE 
traefik-system   LoadBalancer   10.100.154.90   --> 172.31.10.200 <--  80:30336/TCP,443:31639/TCP   64m

Configurer l'entrée DNS pour longhorn.gmolab.net avec l'adresse IP 172.31.10.200

Fichier de configuration

Créer le fichier longhorn-dashboard.yaml

cat << 'EOF' > /tmp/longhorn-dashboard.yaml
# -----------------------------------------------------------------------------
# Middleware pour l'authentification
# -----------------------------------------------------------------------------
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: longhorn-auth-middleware
  namespace: longhorn-system
spec:
  basicAuth:
    secret: longhorn-dashboard-auth
    realm: "Longhorn Authentication"
---
# -----------------------------------------------------------------------------
# Route Ingress
# -----------------------------------------------------------------------------
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: longhorn-dashboard
  namespace: longhorn-system
spec:
  entryPoints:
    - websecure

  routes:
    - match: Host(`longhorn.gmolab.net`) && PathPrefix(`/`)
      kind: Rule

      middlewares:
        - name: longhorn-auth-middleware
      services:
        - name: longhorn-frontend
          port: 80
  tls:
    secretName: longhorn-dashboard-tls
EOF

Appliquer la configuration

kubectl apply -f /tmp/longhorn-dashboard.yaml

Secrets

Authentification pour le dashboard

Installer l'utilitaire htpasswd

sudo dnf install httpd-tools -y

Changer monMotDePasseSecret par un mot de passe de votre choix

kubectl create secret generic longhorn-dashboard-auth \
  -n longhorn-system \
  --from-literal=users="$(htpasswd -nb admin 'monMotDePasseSecret')" \
  --dry-run=client -o yaml | kubectl apply -f -

Certificats

Copier vos fichiers de certificats dans le dossier /tmp et renommer les en tls.crt et tls.key

Créer le secret contenant les certificats

kubectl create secret tls longhorn-dashboord-tls \
  --namespace longhorn-system \
  --cert=/tmp/tls.crt \
  --key=/tmp/tls.key

Problème avec la création de l'objet backup

Pour une raison qui m'échappe, la création de la cible pour les sauvegardes des volumes ne focntionne pas lors du déployement. La commande ci-dessous permet de palier ce problème.

kubectl patch backuptarget.longhorn.io default -n longhorn-system --type merge -p '{"spec": {"backupTargetURL": "s3://longhorn-backups@ch-nyon/", "credentialSecret": "minio-sos-secret"}}'

Version Date Change Auteur
1.1 16.05.2026 Updated longhorn version(1.11.2) GMo
1.1 15.12.2024 Updated longhorn version(1.7.2) GMo
1.0 04.03.2023 Création GMo