Difference between revisions of "Kubeadm upgrade nodes"
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
# New | # New | ||
+ | |||
+ | - https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/ | ||
+ | |||
+ | - Drain node | ||
+ | - On primary update_kubeadm_version then kubeadm_upgrade | ||
+ | - uncordon node | ||
+ | - update_kubeadm_version on all other nodes starting with controllers first | ||
+ | |||
+ | update.sh | ||
``` | ``` | ||
+ | #!/bin/bash | ||
+ | set -eu | ||
+ | |||
update_kubeadm_version(){ | update_kubeadm_version(){ | ||
k8s_minor_version=1.31 | k8s_minor_version=1.31 | ||
Line 15: | Line 27: | ||
sudo systemctl restart kubelet | sudo systemctl restart kubelet | ||
sudo apt-get -y dist-upgrade | sudo apt-get -y dist-upgrade | ||
+ | kubeadm version -o short | ||
+ | echo "Reboot in 10 seconds"; sleep 10 | ||
sudo reboot | sudo reboot | ||
} | } | ||
Line 23: | Line 37: | ||
echo "Updating to version ${k8s_patch_version} in 10 seconds."; sleep 10 | echo "Updating to version ${k8s_patch_version} in 10 seconds."; sleep 10 | ||
sudo kubeadm upgrade plan | sudo kubeadm upgrade plan | ||
+ | sudo killall -s SIGTERM kube-apiserver # trigger a graceful kube-apiserver shutdown | ||
+ | sleep 20 # wait a little bit to permit completing in-flight requests | ||
kubeadm upgrade apply -y ${k8s_patch_version} | kubeadm upgrade apply -y ${k8s_patch_version} | ||
} | } |
Latest revision as of 16:53, 27 December 2024
New
- https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
- Drain node
- On primary update_kubeadm_version then kubeadm_upgrade
- uncordon node
- update_kubeadm_version on all other nodes starting with controllers first
update.sh
#!/bin/bash set -eu update_kubeadm_version(){ k8s_minor_version=1.31 k8s_keyring_file="/etc/apt/keyrings/kubernetes-apt-keyring.gpg" if [ ! -f "${k8s_keyring_file}" ]; then curl -fsSL https://pkgs.k8s.io/core:/stable:/v${k8s_minor_version}/deb/Release.key 2>/dev/null | sudo gpg --dearmor -o ${k8s_keyring_file} fi echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v${k8s_minor_version}/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-mark unhold kubeadm kubectl kubelet && \ sudo apt-get install -y kubelet=${k8s_minor_version}.* kubeadm=${k8s_minor_version}.* kubectl=${k8s_minor_version}.* && \ sudo apt-mark hold kubeadm kubectl kubelet && \ sudo systemctl restart kubelet sudo apt-get -y dist-upgrade kubeadm version -o short echo "Reboot in 10 seconds"; sleep 10 sudo reboot } kubeadm_upgrade_primary_controller(){ k8s_patch_version=$(kubeadm version -o short) echo "Updating to version ${k8s_patch_version} in 10 seconds."; sleep 10 sudo kubeadm upgrade plan sudo killall -s SIGTERM kube-apiserver # trigger a graceful kube-apiserver shutdown sleep 20 # wait a little bit to permit completing in-flight requests kubeadm upgrade apply -y ${k8s_patch_version} }
Old
#!/bin/bash # Update the package lists sudo apt update # Install the Kubernetes packages, specifying the desired version sudo apt install -y kubelet=1.31.* kubeadm=1.31.* kubectl=1.31.* # Restart kubelet service sudo systemctl restart kubelet apt-get upgrade # Verify node status kubectl get nodes -o wide # Optional: Drain the node before upgrading to avoid disruptions # kubectl drain <node-name> --ignore-daemon-sets --force --delete-local-data # Optional: Upgrade other node components (e.g., containerd, Docker) # - Follow the specific upgrade instructions for your container runtime # Note: # - This script assumes you have the Kubernetes repository configured in your system. # - This script uses wildcards to install the latest patch version within the 1.31 series. # - This script performs a rolling update. Consider draining nodes for zero-downtime upgrades. # - Always back up critical data before performing any upgrades. # - Refer to the official Kubernetes documentation for the most up-to-date instructions.