From ab0d6c09ebe761a2fe48c04e5bc314b91b5abf2e Mon Sep 17 00:00:00 2001 From: George Kitsos Date: Wed, 2 Oct 2024 13:11:17 +0300 Subject: [PATCH] fix: Set k3s agent NODE_TOKEN and WIREGUARD_MASTER_VPN_IP --- installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh | 4 +++- installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh | 6 +++++- installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh | 5 +++-- installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh | 6 +++++- k3s/install-kube-k3s-agent-u22-wg.sh | 7 ++++--- k3s/install-kube-k3s-server-u22-wg.sh | 6 ++---- k3s/preinstall-kube-k3s-u22.sh | 2 +- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh b/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh index e6367d4..8192d98 100644 --- a/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh @@ -1,5 +1,7 @@ #!/bin/bash echo "Master install script" +K3S_DEP_PATH=$HOME/k3s + echo "Installing K3s Server" -wget https://raw.githubusercontent.com/eu-nebulous/sal-scripts/main/k3s/install-kube-k3s-server-u22-wg.sh && chmod +x ./install-kube-k3s-server-u22-wg.sh && ./install-kube-k3s-server-u22-wg.sh +sudo -H -u ubuntu bash -c 'wget -P $K3S_DEP_PATH https://raw.githubusercontent.com/eu-nebulous/sal-scripts/dev/k3s/install-kube-k3s-server-u22-wg.sh && chmod +x $K3S_DEP_PATH/install-kube-k3s-server-u22-wg.sh && $K3S_DEP_PATH/install-kube-k3s-server-u22-wg.sh diff --git a/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh b/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh index c9609e4..88eab96 100644 --- a/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh @@ -4,6 +4,10 @@ echo "Master pre-install script\n" echo "Setting hostname\n" sudo hostnamectl set-hostname "$variables_PA_JOB_NAME" +echo "Create K3s Dependencies folder\n" +K3S_DEP_PATH=$HOME/k3s +mkdir -p $K3S_DEP_PATH + echo "Setting Wireguard Interface\n" sudo -H -u ubuntu bash -c 'wget https://raw.githubusercontent.com/eu-nebulous/overlay-network-manager/main/network-manager/bootstrap-agent-scripts/onm/onm-bootstrap.sh && chmod +x onm-bootstrap.sh' sudo -H -u ubuntu bash -c "./onm-bootstrap.sh 'CREATE' $APPLICATION_ID $ONM_URL $PUBLIC_IP $SSH_PORT"; @@ -15,4 +19,4 @@ WIREGUARD_VPN_IP=`ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1` echo "WIREGUARD_VPN_IP= $WIREGUARD_VPN_IP"; echo "Executing k3s-preinstall script\n" -wget https://raw.githubusercontent.com/eu-nebulous/sal-scripts/main/k3s/preinstall-kube-k3s-u22.sh && chmod +x ./preinstall-kube-k3s-u22.sh && ./preinstall-kube-k3s-u22.sh +sudo -H -u ubuntu bash -c 'wget -P $K3S_DEP_PATH https://raw.githubusercontent.com/eu-nebulous/sal-scripts/dev/k3s/preinstall-kube-k3s-u22.sh && chmod +x $K3S_DEP_PATH/preinstall-kube-k3s-u22.sh && $K3S_DEP_PATH/preinstall-kube-k3s-u22.sh diff --git a/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh b/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh index e77cf45..2aa1e31 100644 --- a/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh @@ -2,5 +2,6 @@ echo "Worker install script" echo "Installing K3s Agent" -#TODO: Set K3S_SERVER_WIREGUARD_IP and K3S_SERVER_NODE_TOKEN environmental variables that have been created from K3s Server Installation -wget https://raw.githubusercontent.com/eu-nebulous/sal-scripts/main/k3s/install-kube-k3s-agent-u22-wg.sh && chmod +x ./install-kube-k3s-agent-u22-wg.sh && ./install-kube-k3s-agent-u22-wg.sh $K3S_SERVER_WIREGUARD_IP $K3S_SERVER_NODE_TOKEN +K3S_DEP_PATH=$HOME/k3s + +sudo -H -u ubuntu bash -c 'wget -P $K3S_DEP_PATH https://raw.githubusercontent.com/eu-nebulous/sal-scripts/dev/k3s/install-kube-k3s-agent-u22-wg.sh && chmod +x $K3S_DEP_PATH/install-kube-k3s-agent-u22-wg.sh && $K3S_DEP_PATH/install-kube-k3s-agent-u22-wg.sh diff --git a/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh b/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh index 01c5024..b8bc11c 100644 --- a/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh @@ -4,6 +4,10 @@ echo "Worker pre-install script" echo "Setting hostname\n" sudo hostnamectl set-hostname "$variables_PA_JOB_NAME" +echo "Create K3s Dependencies folder\n" +K3S_DEP_PATH=$HOME/k3s +mkdir -p $K3S_DEP_PATH + echo "Setting Wireguard Interface\n" sudo -H -u ubuntu bash -c 'wget https://raw.githubusercontent.com/eu-nebulous/overlay-network-manager/main/network-manager/bootstrap-agent-scripts/onm/onm-bootstrap.sh && chmod +x onm-bootstrap.sh' sudo -H -u ubuntu bash -c "./onm-bootstrap.sh 'CREATE' $APPLICATION_ID $ONM_URL $PUBLIC_IP $SSH_PORT"; @@ -15,4 +19,4 @@ WIREGUARD_VPN_IP=`ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1` echo "WIREGUARD_VPN_IP= $WIREGUARD_VPN_IP"; echo "Executing k3s-preinstall script\n" -wget https://raw.githubusercontent.com/eu-nebulous/sal-scripts/main/k3s/preinstall-kube-k3s-u22.sh && chmod +x ./preinstall-kube-k3s-u22.sh && ./preinstall-kube-k3s-u22.sh +sudo -H -u ubuntu bash -c 'wget -P $K3S_DEP_PATH https://raw.githubusercontent.com/eu-nebulous/sal-scripts/dev/k3s/preinstall-kube-k3s-u22.sh && chmod +x $K3S_DEP_PATH/preinstall-kube-k3s-u22.sh && $K3S_DEP_PATH/preinstall-kube-k3s-u22.sh diff --git a/k3s/install-kube-k3s-agent-u22-wg.sh b/k3s/install-kube-k3s-agent-u22-wg.sh index 259d8e4..266875e 100644 --- a/k3s/install-kube-k3s-agent-u22-wg.sh +++ b/k3s/install-kube-k3s-agent-u22-wg.sh @@ -11,8 +11,9 @@ LOGFILE="/var/log/install-kube-k3s-agent-u22-wg.$PID.log" sudo touch $LOGFILE sudo chown $USER:$USER $LOGFILE -WIREGUARD_SERVER=$1 -NODE_TOKEN=$2 +WIREGUARD_SERVER=192.168.55.1 +NODE_TOKEN=${APPLICATION_ID} +K3S_VERSION=v1.26.15+k3s1 # All the output of this shell script is redirected to the LOGFILE exec 3>&1 4>&2 @@ -30,7 +31,7 @@ log_print(){ log_print INFO "Installing k3s agent" WIREGUARD_VPN_IP=`ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1` -curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.26.15+k3s1 K3S_URL="https://${WIREGUARD_SERVER}:6443" K3S_TOKEN=${NODE_TOKEN} INSTALL_K3S_EXEC="--node-ip $WIREGUARD_VPN_IP" sh - +curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${K3S_VERSION} K3S_URL="https://${WIREGUARD_SERVER}:6443" K3S_TOKEN=${NODE_TOKEN} INSTALL_K3S_EXEC="--node-ip $WIREGUARD_VPN_IP" sh - # Declare configuration done successfully ENDTIME=$(date +%s) diff --git a/k3s/install-kube-k3s-server-u22-wg.sh b/k3s/install-kube-k3s-server-u22-wg.sh index 516bdd4..9257277 100644 --- a/k3s/install-kube-k3s-server-u22-wg.sh +++ b/k3s/install-kube-k3s-server-u22-wg.sh @@ -15,9 +15,7 @@ sudo chown $USER:$USER $LOGFILE K3S_DEP_PATH=$HOME/k3s CILIUM_VERSION=1.15.5 POD_CIDR=10.244.0.0/16 - -# Create K3s Dependencies folder -mkdir -p $K3S_DEP_PATH +K3S_VERSION=v1.26.15+k3s1 # All the output of this shell script is redirected to the LOGFILE exec 3>&1 4>&2 @@ -34,7 +32,7 @@ log_print(){ log_print INFO "Installing k3s server" WIREGUARD_VPN_IP=`ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1` -curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.26.15+k3s1 INSTALL_K3S_EXEC="--flannel-backend=none --disable-network-policy --bind-address ${WIREGUARD_VPN_IP} --node-ip ${WIREGUARD_VPN_IP} --write-kubeconfig-mode 644" sh - +curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${K3S_VERSION} INSTALL_K3S_EXEC="--cluster-cidr ${POD_CIDR} --token ${APPLICATION_ID} --flannel-backend=none --disable-network-policy --bind-address ${WIREGUARD_VPN_IP} --node-ip ${WIREGUARD_VPN_IP} --write-kubeconfig-mode 644" sh - export KUBECONFIG=/etc/rancher/k3s/k3s.yaml log_print INFO "Setting NODE_TOKEN environmental variable (default expiry 1d)" diff --git a/k3s/preinstall-kube-k3s-u22.sh b/k3s/preinstall-kube-k3s-u22.sh index 549c131..8717296 100644 --- a/k3s/preinstall-kube-k3s-u22.sh +++ b/k3s/preinstall-kube-k3s-u22.sh @@ -62,7 +62,7 @@ Check_lock log_print INFO "Installing curl" sudo apt-get install -y curl || { log_print ERROR "curl installation failed!"; exit $EXITCODE; } -# Turn off the swap momery +# Turn off the swap memory log_print INFO "Turning swap off...." if [ `grep Swap /proc/meminfo | grep SwapTotal: | cut -d" " -f14` == "0" ]; then