diff --git a/p1/scripts/setup-S.sh b/p1/scripts/setup-S.sh index 12f3d81..28c1638 100644 --- a/p1/scripts/setup-S.sh +++ b/p1/scripts/setup-S.sh @@ -6,8 +6,18 @@ echo "Launching k3s install" curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" sh -s - server --cluster-init --node-ip=$S_ADDR --bind-address=$S_ADDR --advertise-address=$S_ADDR # Additional wait to ensure API is responsive (optional but helpful) -echo Waiting -sleep 15 +I=0 +until k3s kubectl get --raw='/readyz' > /dev/null 2>&1; do + echo "Waiting for K3s to be ready..." + sleep 5 + I=$((I+1)) + if [ $I -eq 5 ]; then + echo "threshold gone, ffs" + exit 1 + fi +done + +echo "K3s is ready!" echo "Copying token" cat /var/lib/rancher/k3s/server/node-token > /vagrant/node-token diff --git a/p1/scripts/setup-SW.sh b/p1/scripts/setup-SW.sh index 21108d7..c74680d 100644 --- a/p1/scripts/setup-SW.sh +++ b/p1/scripts/setup-SW.sh @@ -4,16 +4,16 @@ S_ADDR="192.168.56.110" SW_ADDR="192.168.56.111" # In setup-SW.sh, before the k3s install command -# echo "Checking connectivity to server" -# I=0 -# while ! curl -k https://$S_ADDR:6443/healthz > /dev/null 2>&1; do -# echo "Server API not reachable yet, waiting..." -# sleep 5 -# I=$((I+1)) -# if [ $I -eq 5 ]; then -# exit 1 -# fi -# done +echo "Checking connectivity to server" +I=0 +while ! curl -k https://$S_ADDR:6443/readyz > /dev/null 2>&1; do + echo "Server API not reachable yet, waiting..." + sleep 5 + I=$((I+1)) + if [ $I -eq 5 ]; then + exit 1 + fi +done echo "Server is reachable, proceeding with k3s agent install" echo "Waiting for token" diff --git a/p2/scripts/setup-S.sh b/p2/scripts/setup-S.sh index 66af90a..470bba1 100644 --- a/p2/scripts/setup-S.sh +++ b/p2/scripts/setup-S.sh @@ -1,7 +1,20 @@ #!/usr/bin/env sh -echo "Launching k3s install" -curl -sfL https://get.k3s.io | sh -s - server --cluster-init --node-ip=192.168.56.110 +S_ADDR="192.168.56.110" -echo Waiting -sleep 15 +echo "Launching k3s install" +curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" sh -s - server --cluster-init --node-ip=$S_ADDR --bind-address=$S_ADDR --advertise-address=$S_ADDR + +# Wait for K3s to be ready +I=0 +until k3s kubectl get --raw='/healthz' > /dev/null 2>&1; do + echo "Waiting for K3s to be ready..." + sleep 5 + I=$((I+1)) + if [ $I -eq 5 ]; then + echo "threshold gone, ffs" + exit 1 + fi +done + +echo "K3s is ready!"