There are different platforms to run Kubernetes (K8S) nowadays. In cloud, we can consider AWS Elastic Kubernetes Service, Azure Kubernetes Service, or we can install Talos in on-premise infrastructure as quick win solution. However, actually we can install K8S in different Linux distributions. This article will step by step on how to install Kubernetes 1.24.3 in Ubuntu 22.04 with 1 master node and 1 worker node. Since 1.22, platform K8S not support docker swarm and switch to containerd since 1.22, so there has a sigh different during installation. That why I wrote this page for recording.
Steps
- Enable kernal modules for containerd.
In shell, execute command below.sudo cat << EOF | sudo tee /etc/modules-load.d/containerd.conf overlay br_netfilter EOF sudo modprobe overlay sudo modprobe br_netfilter
- Initialize system settings for K8S networking.
In shell, execute command below.sudo cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 EOF sudo sysctl --system
- Prepare applications to use in following steps.
In shell, execute command below.sudo apt update sudo apt install -y apt-transport-https curl
- Disable swap in OS.
In shell, execute command below.sudo swapoff -a sudo sed -i '/ swap / s/^\(.*\)$/#/g' /etc/fstab
- Install containerd
In shell, execute command below.sudo apt install -y ca-certificates curl gnupg lsb-release curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list sudo apt update sudo apt install -y containerd.io
- Configure containerd
In shell, execute command below.sudo mkdir -p /etc/containerd sudo containerd config default | sudo tee /etc/containerd/config.toml sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml && grep 'SystemdCgroup' -B 11 /etc/containerd/config.toml sudo systemctl enable --now containerd sudo systemctl restart containerd
- Install K8S
In shell, execute command below.curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF sudo apt update sudo apt install -y kubelet=$KUBERNETES_VERSION kubectl=$KUBERNETES_VERSION kubeadm=$KUBERNETES_VERSION sudo apt-mark hold kubelet kubeadm kubectl sudo systemctl enable --now kubelet
- [For Master node only] Initialize K8S cluster.
In shell, execute command below.sudo kubeadm init --pod-network-cidr $POD_NETWORK_CIDR --kubernetes-version $KUBERNETES_VERSION
- [For Master node only] Setup master node local settings.
In shell, execute command below.mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
- [For Master node only] Setup Calico.
In shell, execute command below.kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
- [For Master node only] Generate command for worker nodes joining cluster.
In shell, execute command below.kubeadm token create --print-join-command
It should be generate command like this, copy it to clipboard.
- [For Worker node only] Join K8S cluster.
In shell, execute command which copied from previous steps.
- Verify result.
In master node shell, execute command belowkubectl get po -A -o wide
Expected it will show all namespace pods and its deployed pod.
Related shell script has been push in GitHub repository.
Thanks a lot for this helpful information.