advance setup

This commit is contained in:
baschno
2026-04-02 21:13:14 +02:00
parent bb5add7a10
commit 24e56c658a

View File

@@ -157,39 +157,65 @@ stop:
echo "$(($(date +%s) - START_TIME))s"
}
nodenames=$(kubectl get nodes -o=jsonpath="{.items[*]['metadata.name']}")
# for node in ${nodenames}; do
# kubectl drain "${node}" --ignore-daemonsets --delete-emptydir-data --force --disable-eviction --grace-period=60 --timeout=180s 2>&1 || true
# kubectl cordon "${node}"
# echo "Node ${node} stopped."
# done
# echo "Drain complete. Nodes are cordoned and drained."
for node in ${nodenames}; do
kubectl drain "${node}" --ignore-daemonsets --delete-emptydir-data --force --disable-eviction --grace-period=60 --timeout=180s 2>&1 || true
kubectl cordon "${node}"
echo "Node ${node} stopped."
done
echo "Drain complete. Nodes are cordoned and drained."
# if helm status longhorn -n ${LONGHORN_NAMESPACE} &>/dev/null; then
# echo "[$(elapsed)] Waiting for Longhorn volumes to be detached..."
# TIMEOUT=90
# ELAPSED=0
# while [ $ELAPSED -lt $TIMEOUT ]; do
if helm status longhorn -n ${LONGHORN_NAMESPACE} &>/dev/null; then
echo "[$(elapsed)] Waiting for Longhorn volumes to be detached..."
TIMEOUT=90
ELAPSED=0
while [ $ELAPSED -lt $TIMEOUT ]; do
# ATTACHED=$(kubectl get volumes.longhorn.io -n ${LONGHORN_NAMESPACE} -o json 2>/dev/null | \
# jq -r '.items[] | select(.status.state == "attached") | .metadata.name' 2>/dev/null || true)
ATTACHED=$(kubectl get volumes.longhorn.io -n ${LONGHORN_NAMESPACE} -o json 2>/dev/null | \
jq -r '.items[] | select(.status.state == "attached") | .metadata.name' 2>/dev/null || true)
# if [ -z "$ATTACHED" ]; then
# echo "[$(elapsed)] ✓ All Longhorn volumes detached successfully"
# break
# fi
if [ -z "$ATTACHED" ]; then
echo "[$(elapsed)] ✓ All Longhorn volumes detached successfully"
break
fi
# ATTACHED_COUNT=$(echo "$ATTACHED" | grep -c . || echo 0)
# echo " Still waiting for $ATTACHED_COUNT volume(s) to detach..."
# sleep 2
# ELAPSED=$((ELAPSED + 2))
# done
# if [ $ELAPSED -ge $TIMEOUT ]; then
# echo "[$(elapsed)] ⚠ Warning: Timeout waiting for volumes to detach"
# fi
# fi
ATTACHED_COUNT=$(echo "$ATTACHED" | grep -c . || echo 0)
echo " Still waiting for $ATTACHED_COUNT volume(s) to detach..."
sleep 2
ELAPSED=$((ELAPSED + 2))
done
if [ $ELAPSED -ge $TIMEOUT ]; then
echo "[$(elapsed)] ⚠ Warning: Timeout waiting for volumes to detach"
fi
fi
for node in ${nodenames}; do
echo "[$(elapsed)] Stopping and disabling k3s service..."
ssh "${node}" "sudo systemctl stop k3s 2>/dev/null || true"
ssh "${node}" "sudo systemctl disable k3s 2>/dev/null || true"
done
start:
#!/bin/bash
set -euo pipefail
is_schedulable() {
node_name="$1"
! kubectl get node "$node_name" -o jsonpath='{.spec.unschedulable}' 2>/dev/null | grep -q "true"
}
nodenames=$(kubectl get nodes -o=jsonpath="{.items[*]['metadata.name']}")
for node in ${nodenames}; do
echo "Starting k3s service on ${node}..."
if is_schedulable "$node"; then
echo "✓ Node $node is already schedulable"
exit 0
fi
echo "Uncordoning node $node..."
kubectl uncordon "$node" 2>&1 || true
echo "Wait for every node to become Ready..."
done