From 1cdedc26c79364e99dc09009513168bd2ac82bb8 Mon Sep 17 00:00:00 2001 From: "Guillaume B.B. Van Hemmen" Date: Sat, 28 Dec 2024 13:51:25 +0100 Subject: [PATCH] #0000 - Add Longhorn installation script and Helm values file Introduce a bash script (`05_install_longhorn.sh`) to automate the installation of Longhorn using Helm, including S3 backup credentials setup. Include a new Helm values file (`longhorn.yaml`) to define default settings like replica count and S3 backup configuration. --- helm-values/longhorn.yaml | 12 +++++++++ scripts/05_install_longhorn.sh | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 helm-values/longhorn.yaml create mode 100755 scripts/05_install_longhorn.sh diff --git a/helm-values/longhorn.yaml b/helm-values/longhorn.yaml new file mode 100644 index 0000000..e591a36 --- /dev/null +++ b/helm-values/longhorn.yaml @@ -0,0 +1,12 @@ +defaultSettings: + defaultReplicaCount: 2 + storageReservedPercentageForDefaultDisk: 1 + backupTarget: s3://longhorn-talos-backup@eu-west-1/ + backupTargetCredentialSecret: longhorn-s3-secret + +persistence: + defaultClassReplicaCount: 2 + +global: + nodeSelector: + extensions.talos.dev/iscsi-tools: v0.1.6 diff --git a/scripts/05_install_longhorn.sh b/scripts/05_install_longhorn.sh new file mode 100755 index 0000000..4265d8b --- /dev/null +++ b/scripts/05_install_longhorn.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e + +# Check if the Cloudflare API token is provided as an argument +if [ -z "$1" ]; then + echo "Error: Missing S3 access key ID." + echo "Usage: $0 " + echo "You must provide your access key ID as a parameter to run this script." + exit 1 +fi + +# Check if the Cloudflare API token is provided as an argument +if [ -z "$2" ]; then + echo "Error: Missing S3 secret access key ID." + echo "Usage: $0 " + echo "You must provide your secret access key ID as a parameter to run this script." + exit 1 +fi + +AWS_ACCESS_KEY_ID=$1 +AWS_SECRET_ACCESS_KEY=$2 + +# Add the longhorn Helm repository +helm repo add longhorn https://charts.longhorn.io +helm repo update + +# Create the namespace for longhorn +kubectl create namespace longhorn-system || true +kubectl label namespace longhorn-system pod-security.kubernetes.io/enforce=privileged +kubectl label namespace longhorn-system pod-security.kubernetes.io/audit=privileged +kubectl label namespace longhorn-system pod-security.kubernetes.io/warn=privileged + +kubectl delete secret longhorn-s3-secret -n longhorn-system || true +kubectl create secret generic longhorn-s3-secret \ + --namespace longhorn-system \ + --from-literal=AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ + --from-literal=AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ + --from-literal=AWS_REGION=eu-west-1 + +# Install the longhorn chart +helm install longhorn longhorn/longhorn \ + --namespace longhorn-system \ + --version 1.7.2 \ + -f ./helm-values/longhorn.yaml +