|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# curl -sfL https://get.quickstack.dev/setup-canary.sh | sh - |
| 4 | + |
| 5 | +select_network_interface() { |
| 6 | + if [ -z "$INSTALL_K3S_INTERFACE" ]; then |
| 7 | + interfaces_with_ips=$(ip -o -4 addr show | awk '!/^[0-9]*: lo:/ {print $2, $4}' | cut -d'/' -f1) |
| 8 | + |
| 9 | + echo "Available network interfaces:" |
| 10 | + echo "$interfaces_with_ips" |
| 11 | + echo "" |
| 12 | + echo "*******************************************************************************************************" |
| 13 | + echo "" |
| 14 | + echo "If you plan to use QuickStack in a cluster using multiple servers in multiple Networks (private/public)," |
| 15 | + echo "choose the network Interface you want to use for the communication between the servers." |
| 16 | + echo "" |
| 17 | + echo "If you plan to use QuickStack in a single server setup, choose the network Interface with the public IP." |
| 18 | + echo "" |
| 19 | + |
| 20 | + i=1 |
| 21 | + echo "$interfaces_with_ips" | while read -r iface ip; do |
| 22 | + printf "%d) %s (%s)\n" "$i" "$iface" "$ip" |
| 23 | + i=$((i + 1)) |
| 24 | + done |
| 25 | + |
| 26 | + printf "Please enter the number of the interface to use: " |
| 27 | + # Change read to use /dev/tty explicitly |
| 28 | + read -r choice </dev/tty |
| 29 | + |
| 30 | + selected=$(echo "$interfaces_with_ips" | sed -n "${choice}p") |
| 31 | + selected_iface=$(echo "$selected" | awk '{print $1}') |
| 32 | + selected_ip=$(echo "$selected" | awk '{print $2}') |
| 33 | + |
| 34 | + if [ -n "$selected" ]; then |
| 35 | + echo "Selected interface: $selected_iface ($selected_ip)" |
| 36 | + else |
| 37 | + echo "Invalid selection. Exiting." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + fi |
| 41 | + |
| 42 | + echo "Using network interface: $selected_iface with IP address: $selected_ip" |
| 43 | +} |
| 44 | + |
| 45 | +wait_until_all_pods_running() { |
| 46 | + |
| 47 | + # Waits another 5 seconds to make sure all pods are registered for the first time. |
| 48 | + sleep 5 |
| 49 | + |
| 50 | + while true; do |
| 51 | + OUTPUT=$(sudo k3s kubectl get pods -A --no-headers 2>&1) |
| 52 | + |
| 53 | + # Checks if there are no resources found --> Kubernetes ist still starting up |
| 54 | + if echo "$OUTPUT" | grep -q "No resources found"; then |
| 55 | + echo "Kubernetes is still starting up..." |
| 56 | + else |
| 57 | + # Extracts the STATUS column from the kubectl output and filters out the values "Running" and "Completed". |
| 58 | + STATUS=$(echo "$OUTPUT" | awk '{print $4}' | grep -vE '^(Running|Completed)$') |
| 59 | + |
| 60 | + # If the STATUS variable is empty, all pods are running and the loop can be exited. |
| 61 | + if [ -z "$STATUS" ]; then |
| 62 | + echo "Pods started successfully." |
| 63 | + break |
| 64 | + else |
| 65 | + echo "Waiting for all pods to come online..." |
| 66 | + fi |
| 67 | + fi |
| 68 | + |
| 69 | + # Waits for X seconds before checking the pod status again. |
| 70 | + sleep 10 |
| 71 | + done |
| 72 | + |
| 73 | + # Waits another 5 seconds to make sure all pods are ready. |
| 74 | + sleep 5 |
| 75 | + |
| 76 | + sudo kubectl get node |
| 77 | + sudo kubectl get pods -A |
| 78 | +} |
| 79 | + |
| 80 | +# Prompt for network interface |
| 81 | +select_network_interface |
| 82 | + |
| 83 | +# install nfs-common and open-iscsi |
| 84 | +echo "Installing nfs-common..." |
| 85 | +sudo apt-get update |
| 86 | +sudo apt-get install open-iscsi nfs-common -y |
| 87 | + |
| 88 | +# Installation of k3s |
| 89 | +#curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--node-ip=192.168.1.2 --advertise-address=192.168.1.2 --node-external-ip=188.245.236.232 --flannel-iface=enp7s0" INSTALL_K3S_VERSION="v1.31.3+k3s1" sh - |
| 90 | + |
| 91 | +echo "Installing k3s with --flannel-iface=$selected_iface" |
| 92 | +curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-iface=$selected_iface" INSTALL_K3S_VERSION="v1.31.3+k3s1" sh - |
| 93 | +# Todo: Check for Ready node, takes ~30 seconds |
| 94 | +sudo k3s kubectl get node |
| 95 | + |
| 96 | +echo "Waiting for Kubernetes to start..." |
| 97 | +wait_until_all_pods_running |
| 98 | + |
| 99 | +# Installation of Longhorn |
| 100 | +sudo kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/deploy/longhorn.yaml |
| 101 | +echo "Waiting for Longhorn to start..." |
| 102 | +wait_until_all_pods_running |
| 103 | + |
| 104 | +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 105 | +# THIS MUST BE INSTALLED ON ALL NODES --> https://longhorn.io/docs/1.7.2/deploy/install/#installing-nfsv4-client |
| 106 | +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 107 | + |
| 108 | +#sudo kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.6.0/deploy/prerequisite/longhorn-nfs-installation.yaml |
| 109 | +#wait_until_all_pods_running |
| 110 | + |
| 111 | +# Installation of Cert-Manager |
| 112 | +sudo kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.16.1/cert-manager.yaml |
| 113 | +echo "Waiting for Cert-Manager to start..." |
| 114 | +wait_until_all_pods_running |
| 115 | +sudo kubectl -n cert-manager get pod |
| 116 | + |
| 117 | +# Checking installation of Longhorn |
| 118 | +sudo apt-get install jq -y |
| 119 | +sudo curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v1.7.2/scripts/environment_check.sh | bash |
| 120 | + |
| 121 | +joinTokenForOtherNodes=$(sudo cat /var/lib/rancher/k3s/server/node-token) |
| 122 | + |
| 123 | +# deploy QuickStack |
| 124 | +cat <<EOF >quickstack-setup-job.yaml |
| 125 | +apiVersion: v1 |
| 126 | +kind: Namespace |
| 127 | +metadata: |
| 128 | + name: quickstack |
| 129 | +--- |
| 130 | +apiVersion: v1 |
| 131 | +kind: ServiceAccount |
| 132 | +metadata: |
| 133 | + name: qs-service-account |
| 134 | + namespace: quickstack |
| 135 | +--- |
| 136 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 137 | +kind: ClusterRoleBinding |
| 138 | +metadata: |
| 139 | + name: qs-role-binding |
| 140 | +subjects: |
| 141 | + - kind: ServiceAccount |
| 142 | + name: qs-service-account |
| 143 | + namespace: quickstack |
| 144 | +roleRef: |
| 145 | + kind: ClusterRole |
| 146 | + name: cluster-admin |
| 147 | + apiGroup: rbac.authorization.k8s.io |
| 148 | +--- |
| 149 | +apiVersion: batch/v1 |
| 150 | +kind: Job |
| 151 | +metadata: |
| 152 | + name: quickstack-setup-job |
| 153 | + namespace: quickstack |
| 154 | +spec: |
| 155 | + ttlSecondsAfterFinished: 3600 |
| 156 | + template: |
| 157 | + spec: |
| 158 | + serviceAccountName: qs-service-account |
| 159 | + containers: |
| 160 | + - name: quickstack-container |
| 161 | + image: quickstack/quickstack:canary |
| 162 | + env: |
| 163 | + - name: START_MODE |
| 164 | + value: "setup" |
| 165 | + - name: K3S_JOIN_TOKEN |
| 166 | + value: "$joinTokenForOtherNodes" |
| 167 | + imagePullPolicy: Always |
| 168 | + restartPolicy: Never |
| 169 | + backoffLimit: 0 |
| 170 | +EOF |
| 171 | +sudo kubectl apply -f quickstack-setup-job.yaml |
| 172 | +rm quickstack-setup-job.yaml |
| 173 | +wait_until_all_pods_running |
| 174 | +sudo kubectl logs -f job/quickstack-setup-job -n quickstack |
| 175 | + |
| 176 | +# evaluate url to add node to cluster |
| 177 | +# echo "To add an additional node to the cluster, run the following command on the worker node:" |
| 178 | +# echo "curl -sfL https://get.quickstack.dev/setup-worker.sh | K3S_URL=https://<IP-ADDRESS-OR-HOSTNAME-OF-MASTERNODE>:6443 JOIN_TOKEN=$joinTokenForOtherNodes sh -" |
0 commit comments