Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set k3s agent NODE_TOKEN and WIREGUARD_MASTER_VPN_IP #30

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
5 changes: 3 additions & 2 deletions installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
7 changes: 4 additions & 3 deletions k3s/install-kube-k3s-agent-u22-wg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions k3s/install-kube-k3s-server-u22-wg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion k3s/preinstall-kube-k3s-u22.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down