64 lines
No EOL
1.6 KiB
Bash
Executable file
64 lines
No EOL
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Script to update K3s on a node to version 1.33.5
|
|
# Run this script ON each node you want to update
|
|
|
|
set -e
|
|
|
|
NODE_NAME=$(hostname)
|
|
K3S_VERSION="v1.33.5+k3s1"
|
|
|
|
echo "=== Updating K3s on ${NODE_NAME} to ${K3S_VERSION} ==="
|
|
|
|
# Step 1: Check current version
|
|
echo "Current K3s version:"
|
|
k3s --version
|
|
|
|
# Step 2: Drain the node (make workloads move to other nodes)
|
|
echo ""
|
|
echo "Do you want to drain this node first? (recommended for safety)"
|
|
echo "This will move pods to other nodes during the update."
|
|
read -p "Drain node? (y/n): " DRAIN_NODE
|
|
|
|
if [[ "$DRAIN_NODE" == "y" ]]; then
|
|
echo "Draining node ${NODE_NAME}..."
|
|
kubectl drain ${NODE_NAME} --ignore-daemonsets --delete-emptydir-data --force --grace-period=60
|
|
fi
|
|
|
|
# Step 3: Stop K3s service
|
|
echo ""
|
|
echo "Stopping K3s service..."
|
|
sudo systemctl stop k3s
|
|
|
|
# Step 4: Download and install new K3s version
|
|
echo "Installing K3s ${K3S_VERSION}..."
|
|
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="${K3S_VERSION}" INSTALL_K3S_SKIP_START=true sh -
|
|
|
|
# Step 5: Start K3s with new version
|
|
echo "Starting K3s..."
|
|
sudo systemctl start k3s
|
|
|
|
# Step 6: Wait for node to be ready
|
|
echo "Waiting for K3s to be ready..."
|
|
sleep 20
|
|
|
|
# Step 7: Check new version
|
|
echo ""
|
|
echo "New K3s version:"
|
|
k3s --version
|
|
|
|
# Step 8: Check node status
|
|
kubectl get node ${NODE_NAME}
|
|
|
|
# Step 9: Uncordon the node if it was drained
|
|
if [[ "$DRAIN_NODE" == "y" ]]; then
|
|
echo ""
|
|
echo "Uncordoning node ${NODE_NAME}..."
|
|
kubectl uncordon ${NODE_NAME}
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== Update complete on ${NODE_NAME} ==="
|
|
echo ""
|
|
echo "Verify cluster health with:"
|
|
echo " kubectl get nodes"
|
|
echo " kubectl get pods -A | grep -v Running" |