In this Article we are going to learn How to Create Kubernetes cluster using Kubeadm on Ubuntu 22.04 LTS and Join Worker Node to the Cluster.

Prerequisites:

  • 2 Ubuntu 20.04 LTS System with Minimal Installation
  • Minimum 2 or more CPU, 3 GB RAM.
  • SSH Access with sudo privileges

Step1: Login to ubuntu 20.04 instances using your favourite tool

Update & Upgrade Your System:

Start by ensuring your package manager is up-to-date:

ubuntu@ip-172-31-6-61:~$ sudo apt-get update

Step2: Change the hostname:

Setting the hostname on an Ubuntu server permanently involves a couple of steps. Here’s how you can do it:

Open a terminal session and use the hostnamectl command (available on newer versions of Ubuntu):

Syntax: sudo hostnamectl set-hostname new-hostname 

Replace new-hostname with your desired hostname.

sudo hostnamectl set-hostname kubeadm-master (For master)

sudo hostnamectl set-hostname kubeadm-node1 (For node server)

Execute teh above two commands on master and node servers

ubuntu@ip-172-31-2-122:~$ sudo hostnamectl set-hostname kubeadm-master
ubuntu@ip-172-31-6-61:~$ sudo hostnamectl set-hostname kubeadm-node1

Step2: Edit the /etc/hosts file:

Often, you will also want to update the /etc/hosts file to reflect the new hostname, This ensures that the system can resolve its own hostname correctly. Edit the file using a text editor like nano:

syntax: sudo nano /etc/hosts

You might see a line that looks something like: 127.0.1.1 old-hostname Change old-hostname to your new-hostname.

ubuntu@ip-172-31-2-122:~$ sudo nano /etc/hosts

Open the hosts file and comment local IP and and name it as kubeadm-master as show in below image

Save and Exit from nano editor using these options Ctrl X Shift Y Enter

Step3:Reboot (Optional): Although it’s not always necessary, it’s a good idea to reboot your server to ensure that all services recognize the changed hostname:

ubuntu@ip-172-31-2-122:~$ sudo reboot

After the reboot, your server should recognize and use the new hostname permanently. You can always check the current hostname by typing hostname in the terminal.

Output:

Step3: Install apt-transport-https curl

ubuntu@kubeadm-master:~$ sudo apt-get install -y apt-transport-https curl

Next, add docker repository,

ubuntu@kubeadm-master:~$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
ubuntu@kubeadm-master:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

After adding repo, install containerd using script https://get.docker.com/

download the script

ubuntu@kubeadm-master:~$ curl -fsSL https://get.docker.com -o install-docker.sh

run the script either as root, or using sudo to perform the installation.

ubuntu@kubeadm-master:~$ sudo sh install-docker.sh

Once docker installed verify with below commands

ubuntu@kubeadm-master:~$ docker –version

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *