Difference between revisions of "Kubeadm upgrade nodes"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 2: Line 2:
  
 
- https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
 
- 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
 
update.sh

Revision as of 09:46, 23 December 2024

New

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
  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
  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.