diff --git a/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh b/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh index 216119c..e6367d4 100644 --- a/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh @@ -1,11 +1,5 @@ #!/bin/bash echo "Master install script" -wget https://raw.githubusercontent.com/eu-nebulous/sal-scripts/main/k8s/install-kube-u22-wg.sh && chmod +x ./install-kube-u22-wg.sh && ./install-kube-u22-wg.sh - -echo "Installing Helm..." -sudo -H -u ubuntu bash -c ' curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && chmod 700 get_helm.sh && ./get_helm.sh' -# Add KubeVela Helm repository and update - -sudo -H -u ubuntu bash -c 'curl -fsSl https://kubevela.io/script/install.sh | bash' -echo "Configuration complete." +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 diff --git a/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh b/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh index 51d4d67..c9609e4 100644 --- a/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh @@ -1,7 +1,10 @@ #!/bin/bash echo "Master pre-install script\n" +echo "Setting hostname\n" sudo hostnamectl set-hostname "$variables_PA_JOB_NAME" + +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"; echo "" @@ -10,3 +13,6 @@ sleep 60 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 diff --git a/installation-scripts-onm/MASTER_START_SCRIPT.sh b/installation-scripts-onm/MASTER_START_SCRIPT.sh index 27b0235..50cc86f 100644 --- a/installation-scripts-onm/MASTER_START_SCRIPT.sh +++ b/installation-scripts-onm/MASTER_START_SCRIPT.sh @@ -1,26 +1,9 @@ #!/bin/bash echo "Master start script" -WIREGUARD_VPN_IP=`ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1`; -echo "WIREGUARD_VPN_IP=$WIREGUARD_VPN_IP"; -sudo kubeadm init --apiserver-advertise-address ${WIREGUARD_VPN_IP} --service-cidr 10.96.0.0/16 --pod-network-cidr 10.244.0.0/16 - -echo "HOME: $(pwd), USERE: $(id -u -n)" -mkdir -p ~/.kube && sudo cp -i /etc/kubernetes/admin.conf ~/.kube/config && sudo chown $(id -u):$(id -g) ~/.kube/config -id -u ubuntu &> /dev/null - -if [[ $? -eq 0 ]] -then - #USER ubuntu is found - mkdir -p /home/ubuntu/.kube && sudo cp -i /etc/kubernetes/admin.conf /home/ubuntu/.kube/config && sudo chown ubuntu:ubuntu /home/ubuntu/.kube/config -else - echo "User Ubuntu is not found" -fi - - -#sudo -H -u ubuntu kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml; -sudo -H -u ubuntu bash -c 'helm repo add cilium https://helm.cilium.io/ && helm repo update' -sudo -H -u ubuntu bash -c 'helm install cilium cilium/cilium --namespace kube-system --set encryption.enabled=true --set encryption.type=wireguard' +echo "Installing Vela CLI" +sudo -H -u ubuntu bash -c 'curl -fsSl https://kubevela.io/script/install.sh | bash' +echo "Configuration complete." echo "Setting KubeVela..." sudo -H -u ubuntu bash -c 'helm repo add kubevela https://kubevela.github.io/charts && helm repo update' @@ -108,4 +91,4 @@ if [ "$SERVERLESS_ENABLED" == "yes" ]; then kubectl apply -f https://raw.githubusercontent.com/kubevela/samples/master/06.Knative_App/componentdefinition-knative-serving.yaml echo "Serverless installation completed." -fi \ No newline at end of file +fi diff --git a/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh b/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh index 74d80ca..e77cf45 100644 --- a/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh @@ -1,3 +1,6 @@ #!/bin/bash echo "Worker install script" -wget https://raw.githubusercontent.com/eu-nebulous/sal-scripts/main/k8s/install-kube-u22-wg.sh && chmod +x ./install-kube-u22-wg.sh && ./install-kube-u22-wg.sh \ No newline at end of file + +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 diff --git a/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh b/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh index 1992e96..01c5024 100644 --- a/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh +++ b/installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh @@ -1,8 +1,18 @@ #!/bin/bash echo "Worker pre-install script" + +echo "Setting hostname\n" sudo hostnamectl set-hostname "$variables_PA_JOB_NAME" + +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"; +echo "" +echo "" +sleep 60 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 diff --git a/installation-scripts-onm/WORKER_START_SCRIPT.sh b/installation-scripts-onm/WORKER_START_SCRIPT.sh index b48aa3b..898920a 100644 --- a/installation-scripts-onm/WORKER_START_SCRIPT.sh +++ b/installation-scripts-onm/WORKER_START_SCRIPT.sh @@ -1,5 +1,2 @@ #!/bin/bash echo "Worker start script" -sudo kubeadm reset --force -echo $variables_kubeCommand -sudo $variables_kubeCommand diff --git a/k3s/install-kube-k3s-agent-u22-wg.sh b/k3s/install-kube-k3s-agent-u22-wg.sh new file mode 100644 index 0000000..259d8e4 --- /dev/null +++ b/k3s/install-kube-k3s-agent-u22-wg.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Set up the script variables +STARTTIME=$(date +%s) +PID=$(echo $$) +EXITCODE=$PID +DATE=$(date) +LOGFILE="/var/log/install-kube-k3s-agent-u22-wg.$PID.log" + +# Set up the logging for the script +sudo touch $LOGFILE +sudo chown $USER:$USER $LOGFILE + +WIREGUARD_SERVER=$1 +NODE_TOKEN=$2 + +# All the output of this shell script is redirected to the LOGFILE +exec 3>&1 4>&2 +trap 'exec 2>&4 1>&3' 0 1 2 3 +exec 1>$LOGFILE 2>&1 + +# A function to print a message to the stdout as well as as the LOGFILE +log_print(){ + level=$1 + Message=$2 + echo "$level [$(date)]: $Message" + echo "$level [$(date)]: $Message" >&3 +} + +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 - + +# Declare configuration done successfully +ENDTIME=$(date +%s) +ELAPSED=$(( ENDTIME - STARTTIME )) +log_print INFO "Configuration done successfully in $ELAPSED seconds " diff --git a/k3s/install-kube-k3s-server-u22-wg.sh b/k3s/install-kube-k3s-server-u22-wg.sh new file mode 100644 index 0000000..516bdd4 --- /dev/null +++ b/k3s/install-kube-k3s-server-u22-wg.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# Set up the script variables +STARTTIME=$(date +%s) +PID=$(echo $$) +EXITCODE=$PID +DATE=$(date) +LOGFILE="/var/log/install-kube-k3s-server-u22-wg.$PID.log" + +# Set up the logging for the script +sudo touch $LOGFILE +sudo chown $USER:$USER $LOGFILE + +# Variables +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 + +# All the output of this shell script is redirected to the LOGFILE +exec 3>&1 4>&2 +trap 'exec 2>&4 1>&3' 0 1 2 3 +exec 1>$LOGFILE 2>&1 + +# A function to print a message to the stdout as well as as the LOGFILE +log_print(){ + level=$1 + Message=$2 + echo "$level [$(date)]: $Message" + echo "$level [$(date)]: $Message" >&3 +} + +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 - +export KUBECONFIG=/etc/rancher/k3s/k3s.yaml + +log_print INFO "Setting NODE_TOKEN environmental variable (default expiry 1d)" +NODE_TOKEN=$(sudo cat /var/lib/rancher/k3s/server/token) +log_print INFO "NODE_TOKEN: ${NODE_TOKEN}" + +log_print INFO "Installing Helm..." +curl -fsSL -o $K3S_DEP_PATH/get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && chmod 700 $K3S_DEP_PATH/get_helm.sh && $K3S_DEP_PATH/get_helm.sh + +log_print INFO "Adding Cilium Repo" +# Add Cilium Helm Repo +helm repo add cilium https://helm.cilium.io/ +helm repo update + +log_print INFO "Installing Cilium" +# Install Cilium with Wireguard parameters +helm install cilium cilium/cilium \ + --version $CILIUM_VERSION \ + --namespace kube-system \ + --set ipam.mode=cluster-pool \ + --set ipam.operator.clusterPoolIPv4PodCIDRList=$POD_CIDR \ + --set encryption.enabled=true \ + --set encryption.type=wireguard + +# Declare configuration done successfully +ENDTIME=$(date +%s) +ELAPSED=$(( ENDTIME - STARTTIME )) +log_print INFO "Configuration done successfully in $ELAPSED seconds " diff --git a/k3s/preinstall-kube-k3s-u22.sh b/k3s/preinstall-kube-k3s-u22.sh new file mode 100644 index 0000000..549c131 --- /dev/null +++ b/k3s/preinstall-kube-k3s-u22.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# This bash script is designed to prepare and install Kubernetes K3s Distribution for Ubuntu 22.04. +# If an error occur, the script will exit with the value of the PID to point at the logfile. + +# Set up the script variables +STARTTIME=$(date +%s) +PID=$(echo $$) +EXITCODE=$PID +DATE=$(date) +LOGFILE="/var/log/preinstall-kube-k3s-u22.$PID.log" + +# Set up the logging for the script +sudo touch $LOGFILE +sudo chown $USER:$USER $LOGFILE + +# All the output of this shell script is redirected to the LOGFILE +exec 3>&1 4>&2 +trap 'exec 2>&4 1>&3' 0 1 2 3 +exec 1>$LOGFILE 2>&1 + +# A function to print a message to the stdout as well as as the LOGFILE +log_print(){ + level=$1 + Message=$2 + echo "$level [$(date)]: $Message" + echo "$level [$(date)]: $Message" >&3 +} + +# A function to check for the apt lock +Check_lock() { + i=0 + log_print INFO "Checking for apt lock" + while [ `ps aux | grep [l]ock_is_held | wc -l` != 0 ]; do + echo "Lock_is_held $i" + ps aux | grep [l]ock_is_held + sleep 10 + ((i=i+10)); + done + log_print INFO "Exited the while loop, time spent: $i" + echo "ps aux | grep apt" + ps aux | grep apt + log_print INFO "Waiting for lock task ended properly." +} + +# Start the Configuration +log_print INFO "Configuration started!" +log_print INFO "Logs are saved at: $LOGFILE" + +# Check for lock +Check_lock + +# Update the package list +log_print INFO "Updating the package list." +sudo apt-get update +sudo unattended-upgrade -d + +# Check for lock +Check_lock + +# Install curl +log_print INFO "Installing curl" +sudo apt-get install -y curl || { log_print ERROR "curl installation failed!"; exit $EXITCODE; } + +# Turn off the swap momery +log_print INFO "Turning swap off...." +if [ `grep Swap /proc/meminfo | grep SwapTotal: | cut -d" " -f14` == "0" ]; +then + log_print INFO "The swap memory is Off" +else + sudo swapoff -a || { log_print ERROR "Temporary swap memory can't be turned off "; exit $EXITCODE; } + sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab || { log_print ERROR "swap memory can't be turned off "; exit $EXI +TCODE; } + log_print INFO "Swap turned off!" +fi + +# Declare configuration done successfully +ENDTIME=$(date +%s) +ELAPSED=$(( ENDTIME - STARTTIME )) +log_print INFO "Configuration done successfully in $ELAPSED seconds "