Difference between revisions of "Cka kubeadm init upgrade"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 11: Line 11:
 
   sudo apt install apt-transport-https curl -y
 
   sudo apt install apt-transport-https curl -y
  
 +
  # https://kubernetes.io/docs/setup/production-environment/container-runtimes/
 
   sudo apt install containerd -y
 
   sudo apt install containerd -y
 
   sudo mkdir -p /etc/containerd
 
   sudo mkdir -p /etc/containerd
Line 20: Line 21:
 
   sudo sysctl --system
 
   sudo sysctl --system
  
 +
  # https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl
 
   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
 
   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
 
   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
Line 30: Line 32:
 
   sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
 
   sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
  
   # overlay is modprobed by containerd
+
   # overlay is already modprobed by containerd
 
   sudo modprobe br_netfilter
 
   sudo modprobe br_netfilter
 
   echo -e "br_netfilter" | sudo tee /etc/modules-load.d/k8s.conf
 
   echo -e "br_netfilter" | sudo tee /etc/modules-load.d/k8s.conf

Revision as of 06:56, 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

  # https://kubernetes.io/docs/setup/production-environment/container-runtimes/
  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
  echo "net.ipv4.ip_forward = 1" | /etc/sysctl.d/k8s.conf
  sudo sysctl --system

  # https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl
  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 already 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 "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bashrc
  sudo reboot
}

prep_k8s_node