-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlonghorn-install.sh
More file actions
executable file
·84 lines (70 loc) · 2.86 KB
/
Copy pathlonghorn-install.sh
File metadata and controls
executable file
·84 lines (70 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Longhorn Installation Script for Talos Kubernetes Cluster
# This script installs Longhorn and configures storage on all worker nodes
set -e
echo "=== Longhorn Installation for Talos ==="
# Check prerequisites
if ! command -v kubectl &> /dev/null; then
echo "Error: kubectl is not installed"
exit 1
fi
if ! command -v helm &> /dev/null; then
echo "Error: helm is not installed"
exit 1
fi
# Add Longhorn Helm repo
echo "Adding Longhorn Helm repository..."
helm repo add longhorn https://charts.longhorn.io 2>/dev/null || true
helm repo update
# Create namespace with pod security labels
echo "Creating longhorn-system namespace..."
kubectl create namespace longhorn-system 2>/dev/null || true
kubectl label namespace longhorn-system \
pod-security.kubernetes.io/enforce=privileged \
pod-security.kubernetes.io/audit=privileged \
pod-security.kubernetes.io/warn=privileged \
--overwrite
# Install Longhorn
echo "Installing Longhorn..."
helm upgrade --install longhorn longhorn/longhorn \
--namespace longhorn-system \
--set defaultSettings.createDefaultDiskLabeledNodes=true \
--set persistence.defaultClassReplicaCount=3 \
--wait --timeout 5m
# Wait for Longhorn manager pods to be ready
echo "Waiting for Longhorn manager pods..."
kubectl wait --for=condition=ready pod -l app=longhorn-manager -n longhorn-system --timeout=300s
# Expose Longhorn UI via NodePort
echo "Exposing Longhorn UI on NodePort 30080..."
kubectl patch svc longhorn-frontend -n longhorn-system \
-p '{"spec": {"type": "NodePort", "ports": [{"port": 80, "targetPort": 8000, "nodePort": 30080}]}}'
# Get worker nodes
WORKER_NODES=$(kubectl get nodes --no-headers -o custom-columns=":metadata.name" | grep worker)
# Configure disks on each worker node
echo "Configuring storage disks on worker nodes..."
for node in $WORKER_NODES; do
echo " Configuring disk on $node..."
kubectl patch nodes.longhorn.io "$node" -n longhorn-system --type='merge' \
-p '{"spec":{"disks":{"default-disk":{"path":"/var/lib/longhorn","allowScheduling":true,"storageReserved":0}}}}'
done
# Wait for disks to be ready
echo "Waiting for disks to initialize..."
sleep 10
# Verify disk status
echo ""
echo "=== Longhorn Storage Status ==="
for node in $WORKER_NODES; do
STORAGE=$(kubectl get nodes.longhorn.io "$node" -n longhorn-system -o jsonpath='{.status.diskStatus.default-disk.storageAvailable}' 2>/dev/null || echo "0")
STORAGE_GB=$((STORAGE / 1024 / 1024 / 1024))
echo " $node: ${STORAGE_GB} GB available"
done
echo ""
echo "=== Longhorn Installation Complete ==="
echo ""
echo "Longhorn UI available at:"
echo " http://<worker-node-ip>:30080"
echo ""
echo "Worker node IPs:"
kubectl get nodes -l '!node-role.kubernetes.io/control-plane' -o wide --no-headers | awk '{print " " $1 ": " $6}'
echo ""
echo "StorageClass 'longhorn' is now the default storage class."