A step-by-step guide to install Kubernetes cluster on Ubuntu 22.04 using Kubeadm command .
Master Node: 192.168.1.100 master01.tracston.com
Worker Node: 192.168.1.101 – worker01.tracston.com
Worker Node: 192.168.1.102 – worker02.tracston.com
Note: Change the hostname to your domain
Note: Taking into consideration multi master setup
Set hostname and add entries in the hosts file
Login to to master node and set hostname using hostnamectl command,
sudo hostnamectl set-hostname “master01.tracston.com”
On the worker nodes
sudo hostnamectl set-hostname “worker01.tracston.com”
sudo hostnamectl set-hostname “worker02.tracston.com”
Add the following entries in /etc/hosts file on each node
192.168.1.100 master01.tracston.com
192.168.1.101 worker01.tracston.com
192.168.1.102 worker02.tracston.com
Disable swap & add kernel settings
sudo swapoff -a
sudo sed -i ‘/ swap / s/^\(.*\)$/#\1/g’ /etc/fstab
Load the following kernel modules on all the nodes,
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOFsudo modprobe overlay
sudo modprobe br_netfilter
Set the following Kernel parameters for Kubernetes, run beneath tee command
sudo tee /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
#Reload new settings
sudo sysctl –system
Install Docker
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
Enable docker repository
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
sudo apt update
sudo apt install -y containerd.io
Configure containerd to start using systemd as cgroup.
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1
sudo sed -i ‘s/SystemdCgroup \= false/SystemdCgroup \= true/g’ /etc/containerd/config.toml
Restart and enable containerd service
sudo systemctl restart containerd
sudo systemctl enable containerd
Install kubernetes
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add –
sudo apt-add-repository “deb http://apt.kubernetes.io/ kubernetes-xenial main”
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Initialize Kubernetes cluster with Kubeadm command
Kubeadm init –pod-network-cidr=10.0.0.0/16
To work with the newly created cluster copy the configuration file to your home dir
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Check Cluster Status
kubectl cluster-info
Follow the same for installation on the nodes
When finished installing the master node there was an output command how to join new worker nodes to the cluster
Run the following command to join the node to the cluster
sudo kubeadm join k8smaster.example.net:6443 –token xxxxxxxxxxxxxxxxxxxxxx \
–discovery-token-ca-cert-hash sha256:0494aa7fc6ced8tj984yuetjhglkefdhjw98utw616656932ff9173c94962a36
Check the nodes status from master node
kubectl get nodes
Install Networking Calico
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
#Download the custom resources if you wish to customize Calico
curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml -O
kubectl create -f custom-resources.yaml
Check the nodes status. should be status Ready
kubectl get nodes
Attachment: commands.txt
To reset the configuration of an existing kubernetes type
kubeadm reset
We do this for a living.
Kubernetes, DevOps and platform engineering, delivered in days — not another weekend lost to a stack trace.
Start a project →