Setting Up Kubernetes in AWS ubuntu 20.04 with kubeadm

Log in to AWS

After login into the AWS. Create 3 instances. 1 for the Master node and the other 2 for the worker Node

Make sure that the Master node is t2.medium because the master node must have 2 vCPU and 4GB of Ram.

Also, ensure that the security group selects all traffic from anywhere.

Update the package index and upgrade the system packages

sudo apt-get update
sudo apt-get upgrade -y

Install ‘apt-transport-https’, docker

sudo apt-get install apt-transport-https

This package is required to enable ‘apt’ to retrieve packages from repositories accessed over HTTPS.

Kubernetes packages are hosted on the Google Cloud Package Repository and accessed over HTTPS. Therefore, ‘apt-transport-https’ is required to be able to retrieve the Kubernetes packages from this repository.

sudo apt-get install -y

The docker engine is the runtime engine.

Add the kubernetes apt repository and gpg key

curl -s | sudo apt-key add -

echo "deb kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

The first command downloads the GPG key for the Kubernetes package repository and adds it to the system’s list of trusted keys.

The GPG key is used to verify the authenticity of the Kubernetes packages that will be downloaded from the Kubernetes package repository.

The second command is used to add the new package repository of Kubernetes to the ‘apt’ package manager on a system running Ubuntu 16.04(xenial) or later. After adding this repository to the system’s package sources, we can install and manage the Kubernetes package using apt.

Update the package index and install kubeadm, kubelet, kubectl

sudo apt-get update

sudo apt-get install -y kubeadm=1.20.0-00 kubelet=1.20.0-00 kubectl=1.20.0-00

Ensure to specify the given version number.

Initialize the cluster using ‘kubeadm’(Only in master)

sudo kubeadm init

The required configuration files will be generated by this command, and the control plane components will be started. Additionally, it will generate a command that you can use to add worker nodes to the cluster, something like this:

kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>

mkdir -p $HOME/.kube 
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config 
sudo chown $(id -u):$(id -g) $HOME/.kube/config

The admin.conf file is needed to authenticate the user with the cluster's API server, and the .kube/config file is used to store this configuration information. By copying the admin.conf file to .kube/config and changing its ownership, the user can access the cluster using the kubectl command-line tool and manage the cluster using the Kubernetes API.

Apply the CNI(Container Network Interface)

kubectl apply -f

The CNI plugins in Kubernetes is to provide a flexible and extensible networking solution like assigning IP addresses to pods and routing traffic between pods and between the cluster and the outside world. The most commonly used plugins are ‘flannel’, ‘calico’, and ‘weave’. Each plugin has its own advantage. In our case, we are using ‘calico’.

Join the nodes to the master (Only in Nodes)

To join the nodes to the master, copy the ‘kubeadm join …..’ command from step 6 and apply the command to the node.

Now in the master node type

kubectl get nodes

We can see the nodes running as shown in the image below