Difference between revisions of "Cka kubeadm init upgrade"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with "## Init Ubuntu 24.04 & 22.04 ``` #!/bin/bash set -eu k8s_minor_version=1.31 prep_k8s_node(){ sudo apt update && sudo apt upgrade -y sudo apt install apt-transport-https...")
 
Line 24: Line 24:
 
   sudo apt-mark hold kubelet kubeadm kubectl
 
   sudo apt-mark hold kubelet kubeadm kubectl
  
 +
  swapon -s # returns summary text if swap is enabled
 
   sudo swapoff -a
 
   sudo swapoff -a
 
   sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
 
   sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Revision as of 06:51, 4 January 2025

Init Ubuntu 24.04 & 22.04

#!/bin/bash
set -eu

k8s_minor_version=1.31

prep_k8s_node(){
  sudo apt update && sudo apt upgrade -y
  sudo apt install apt-transport-https curl -y

  sudo apt install containerd -y
  sudo mkdir -p /etc/containerd
  containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
  #  Instruct containerd to use the Systemd cgroup hierarchy (typically cgroupv2) for managing container resources.
  sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
  sudo systemctl restart containerd

  curl -fsSL https://pkgs.k8s.io/core:/stable:/v${k8s_minor_version}/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
  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 update
  sudo apt install -y kubelet kubeadm kubectl
  sudo apt-mark hold kubelet kubeadm kubectl

  swapon -s # returns summary text if swap is enabled
  sudo swapoff -a
  sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

  # overlay is modprobed by containerd
  sudo modprobe br_netfilter
  echo -e "br_netfilter" | sudo tee /etc/modules-load.d/k8s.conf
  lsmod | grep overlay
  lsmod | grep br_netfilter

  echo "net.ipv4.ip_forward                 = 1" | /etc/sysctl.d/k8s.conf
  sudo sysctl --system

  echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bashrc
  sudo reboot
}

prep_k8s_node