-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster-upgrade.sh
More file actions
executable file
·47 lines (37 loc) · 1.35 KB
/
cluster-upgrade.sh
File metadata and controls
executable file
·47 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Cluster upgrade procedure (e.g., 1.30 → 1.31)
# Run on each node, control plane first
set -euo pipefail
TARGET_VERSION="${1:?Usage: $0 <target-version> (e.g., 1.31.0)}"
NODE_NAME=$(hostname)
ROLE="${2:-worker}" # "control-plane" or "worker"
echo "=== Upgrading $NODE_NAME ($ROLE) to v${TARGET_VERSION} ==="
# Step 1: Drain the node (run from a machine with kubectl access)
echo "[1/5] Drain node..."
echo " kubectl drain $NODE_NAME --ignore-daemonsets --delete-emptydir-data"
# Step 2: Upgrade kubeadm
echo "[2/5] Upgrading kubeadm..."
sudo apt-get update
sudo apt-get install -y --allow-change-held-packages kubeadm="${TARGET_VERSION}-*"
kubeadm version
# Step 3: Apply upgrade
if [ "$ROLE" = "control-plane" ]; then
echo "[3/5] Planning upgrade..."
sudo kubeadm upgrade plan
echo "[3/5] Applying upgrade..."
sudo kubeadm upgrade apply "v${TARGET_VERSION}" --yes
else
echo "[3/5] Upgrading worker node config..."
sudo kubeadm upgrade node
fi
# Step 4: Upgrade kubelet and kubectl
echo "[4/5] Upgrading kubelet and kubectl..."
sudo apt-get install -y --allow-change-held-packages \
kubelet="${TARGET_VERSION}-*" \
kubectl="${TARGET_VERSION}-*"
sudo systemctl daemon-reload
sudo systemctl restart kubelet
# Step 5: Uncordon
echo "[5/5] Uncordon node..."
echo " kubectl uncordon $NODE_NAME"
echo "=== Done. Verify with: kubectl get nodes ==="