DEV Community

Abdallah Kordy
Abdallah Kordy

Posted on

Kubernetes installation

These instructions are for Kubernetes v1.30 (debian-based) controlplane & worker node

  1. Update the apt package index install packages needed to use the Kubernetes apt repository:
sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
Enter fullscreen mode Exit fullscreen mode

2.Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:

# If the directory `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.
# sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Enter fullscreen mode Exit fullscreen mode

3.Add the appropriate Kubernetes apt repository. Please note that this repository have packages only for Kubernetes 1.30; for other Kubernetes minor versions, you need to change the Kubernetes minor version in the URL to match your desired minor version (you should also check that you are reading the documentation for the version of Kubernetes that you plan to install).

# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Enter fullscreen mode Exit fullscreen mode

4.Update the apt package index, install kubelet, kubeadm and kubectl, and pin their version:

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Enter fullscreen mode Exit fullscreen mode

5.(Optional) Enable the kubelet service before running kubeadm:

sudo systemctl enable --now kubelet
Enter fullscreen mode Exit fullscreen mode

6.
You might know about swap space on hard drives, which OS systems try to use as if it were RAM. Operating systems try to move less frequently accessed data to the swap space to free up RAM for more immediate tasks. However, accessing data in swap is much slower than accessing data in RAM because hard drives are slower than RAM.

Kubernetes schedules work based on the understanding of available resources. If workloads start using swap, it can become difficult for Kubernetes to make accurate scheduling decisions. Therefore, it’s recommended to disable swap before installing Kubernetes.

sudo swapoff 
Enter fullscreen mode Exit fullscreen mode
sudo sed -i '/ swap / s/^/#/' /etc/fstab
Enter fullscreen mode Exit fullscreen mode

8.
To configure the IPV4 bridge on all nodes, execute the following commands on each node

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
Enter fullscreen mode Exit fullscreen mode
# sysctl params required by setup, params persist across reboots
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

# Apply sysctl params without reboot
sudo sysctl --system
Enter fullscreen mode Exit fullscreen mode

9.
install containerd Runtime

 sudo apt install containerd 
 sudo mkdir /etc/containerd

Enter fullscreen mode Exit fullscreen mode

10.
Then, create a default configuration file for containerd and save it as config.toml using the

containerd config default > /etc/containerd/config.toml
Enter fullscreen mode Exit fullscreen mode

11.

sudo sed -i 's/ SystemdCgroup = false/ SystemdCgroup = true/' /etc/containerd/config.toml
Enter fullscreen mode Exit fullscreen mode

12.
restart containerd & kubelet so as change take effect

sudo systemctl restart containerd.service
sudo systemctl restart kubelet.service

Enter fullscreen mode Exit fullscreen mode

13.

sudo kubeadm config images pull
Enter fullscreen mode Exit fullscreen mode

14
configure best & secured network plugin (kubernetes )

kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml
Enter fullscreen mode Exit fullscreen mode

Top comments (0)