Skip to content

Commit

Permalink
Merge with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Iqqdd99 committed Oct 2, 2024
2 parents ff26e76 + b1b74f3 commit 444030d
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 32 deletions.
10 changes: 3 additions & 7 deletions installation-scripts-onm/MASTER_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/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
K3S_DEP_PATH=$HOME/k3s

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"
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
10 changes: 10 additions & 0 deletions installation-scripts-onm/MASTER_PRE_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/bin/bash
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";
echo ""
Expand All @@ -10,3 +17,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"
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
25 changes: 4 additions & 21 deletions installation-scripts-onm/MASTER_START_SCRIPT.sh
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -122,4 +105,4 @@ if [ "$WORKFLOW_ENABLED" == "yes" ]; then
kubectl -n argo create rolebinding default --role=argo-workflows-workflow --serviceaccount=argo:default;

echo "Workflow installation completed.";
fi
fi
6 changes: 5 additions & 1 deletion installation-scripts-onm/WORKER_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/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

echo "Installing K3s Agent"
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
14 changes: 14 additions & 0 deletions installation-scripts-onm/WORKER_PRE_INSTALL_SCRIPT.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
#!/bin/bash
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";
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"
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
3 changes: 0 additions & 3 deletions installation-scripts-onm/WORKER_START_SCRIPT.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/bin/bash
echo "Worker start script"
sudo kubeadm reset --force
echo $variables_kubeCommand
sudo $variables_kubeCommand
39 changes: 39 additions & 0 deletions k3s/install-kube-k3s-agent-u22-wg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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=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
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=${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)
ELAPSED=$(( ENDTIME - STARTTIME ))
log_print INFO "Configuration done successfully in $ELAPSED seconds "
63 changes: 63 additions & 0 deletions k3s/install-kube-k3s-server-u22-wg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/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
K3S_VERSION=v1.26.15+k3s1

# 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=${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)"
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 "
80 changes: 80 additions & 0 deletions k3s/preinstall-kube-k3s-u22.sh
Original file line number Diff line number Diff line change
@@ -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 memory
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 "

0 comments on commit 444030d

Please sign in to comment.