How to Install Kubernetes Cluster on Debian 11 with Kubeadm
======
Are you looking for an easy guide for installing Kubernetes Cluster on Debian 11 (Bullseye)?
The step-by-step guide on this page will demonstrate you how to install Kubernetes cluster on Debian 11 with Kubeadm utility.
Kubernetes (k8s) cluster contains master and worker nodes which are used to run containerized applications. Master node works as control plan and worker nodes offers environment for actual workload.
##### Prerequisites
* Minimal Installed Debian 11
* 2 CPU / vCPU
* 2 GB RAM
* 20 GB free disk space
* Sudo User with Admin rights
* Stable Internet Connectivity
##### Lab Setup
For the demonstration, I am using three Debian 11 systems with following details,
* Master Node (k8s-master) – 192.168.1.236
* Worker Node 1 (k8s-worker1) – 192.168.1.237
* Worker Node 2 (k8s-worker2) – 192.168.1.238
Without any further delay, let’s jump into the installation steps.
### 1 ) Set Host Name and update /etc/hosts file
Use hostnamectl command to set the hostname on master and worker nodes.
```
$ sudo hostnamectl set-hostname "k8s-master"// Run on master node
$ sudo hostnamectl set-hostname "k8s-worker1"// Run on 1st worker node
$ sudo hostnamectl set-hostname "k8s-worker2" // Run on 2nd worker node
```
Add the following entries in /etc/hosts file on all the nodes,
```
192.168.1.236 k8s-master
192.168.1.237 k8s-worker1
192.168.1.238 k8s-worker2
```
### 2) Disable Swap on all nodes
For kubelet to work smoothly, it is recommended to disable swap. Run following commands on master and worker nodes to turn off swap.
```
$ sudo swapoff -a
$ sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
```
### 3) Configure Firewall Rules for Kubernetes Cluster
In case, OS firewall is enabled on your debian systems then allow following ports on master and worker nodes respectively.
On Master node, run
```
$ sudo ufw allow 6443/tcp
$ sudo ufw allow 2379/tcp
$ sudo ufw allow 2380/tcp
$ sudo ufw allow 10250/tcp
$ sudo ufw allow 10251/tcp
$ sudo ufw allow 10252/tcp
$ sudo ufw allow 10255/tcp
$ sudo ufw reload
```
On Worker Nodes,
```
$ sudo ufw allow 10250/tcp
$ sudo ufw allow 30000:32767/tcp
$ sudo ufw reload
```
Note: If firewall is disabled on your Debian 11 systems, then you can skip this step.
### 4) Install Containerd run time on all nodes
Containerd is the industry standard container run time, we must install containerd on all master and worker nodes.
Before installing containerd, set the following kernel parameters on all the nodes.
Now, install conatinerd by running following apt command on all the nodes.
```
$ sudo apt update
$ sudo apt -y install containerd
```
Configure containerd so that it works with Kubernetes, run beneath command on all the nodes
```
$ containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1
```
Set cgroupdriver to systemd on all the nodes,
Edit the file ‘/etc/containerd/config.toml’ and look for the section ‘[plugins.”io.containerd.grpc.v1.cri”.containerd.runtimes.runc.options]’ and add SystemdCgroup = true
```
$ sudo vi /etc/containerd/config.toml
```
![systemdCgroup-true-containerd-config-toml][1]
Save and close the file.
Restart and enable containerd service on all the nodes,
```
$ sudo systemctl restart containerd
$ sudo systemctl enable containerd
```
### 5) Enable Kubernetes Apt Repository
Enable Kubernetes apt repository on all the nodes, run
Above output confirms that control plane has been initialized successfully. In the output, we have commands for regular user for interacting with the cluster and also the command to join any worker node to this cluster.
To start interacting with cluster, run following commands on master node,
Above command’s output confirm that we are able to access our nginx based application.
That’s all from this guide, I hope you have found it informative and able to install Kubernetes cluster on Debian 11 smoothly. Kindly do post your queries and feedback in below comments section.