Introduction:

In today’s rapidly evolving tech landscape, containerization has emerged as the darling of the software development world. Containers provide an efficient, scalable, and consistent environment to build, ship, and run applications. But as organizations started to deploy more containers, managing them manually or through custom scripts proved cumbersome and ineffective. Enter the world of container orchestration.Building a Kubernetes cluster with kubeadm is a popular choice for developers and system administrators. In this guide, we’ll demonstrate how to bootstrap a simple two-node Kubernetes cluster using kubeadm on Ubuntu OS. Now we will see “How to Install Kubernetes Cluster on Ubuntu 20.04 LTS with kubeadm”.

Prerequisites

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

Note: I am working as root user, it is not a madatory to be a root user to run these commands but as a ubuntu user you will face one error which can be rectified by some commands which is present in this blog.

Steps to Setup Kubeadm with Node in Linux Ubuntu OS

Suggestion: For an Identification Please Change the Host names as master and nodes for better identification.

sudo vi /etc/hostname
"Master or Node"

Preparing Both Nodes:

Follow these steps on both nodes:

a. Update System:

sudo apt-get update
sudo apt upgrade -y

b. Install Docker:

curl -fsSL https://get.docker.com -o install-docker.sh

sudo sh install-docker.sh

c. Add the Docker Daemon configurations to use systemd as the cgroup driver.

cat <<EOF | sudo tee /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

Verify the Docker images.

docker images

Note: If your working as a ubuntu user you will get an error that permission denied.

To Resolve the permission denied error we need to run below commands:

sudo usermod -aG docker $USER

sudo chmod 666 /var/run/docker.sock

d. Add Kubernetes Repository:

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update

e. Install Kubeadm, Kubelet, and Kubectl:

sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Setting Up the Master Node:

On the machine you want as the master node:

a. Initialize Master Node:

sudo kubeadm init

You will Find the Error as above.

To rectify the above Error we need to run below commands in “Master and Node servers”.

sudo rm /etc/containerd/config.toml

sudo systemctl restart containerd

Now try again Kubeadm init , Either the error resolved or not

sudo kubeadm init

Output: In this we can get the token which is used to run in the nodes with “kubeadm join”.

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.31.6.177:6443 --token vr5rat.seyprj6jvw4xy43m \
        --discovery-token-ca-cert-hash sha256:4c9b53eb03744b4cf21c5bdacd712024eb09030561714cc554583848hvsss516

After the initialization completes, set up the local kubeconfig:

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

b. Install a Pod Network:

We’ll use Calico as the pod network:

curl https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml -O

To apply the Calico file:

kubectl apply -f calico.yaml

Setting Up the Worker Node:

On the machine you’ve designated as the worker node:

Join the worker node to the master. You would have received a kubeadm join command at the end of the master initialization. It looks something like this:

sudo kubeadm join [your-master-ip]:6443 --token [your-token] --discovery-token-ca-cert-hash [your-hash]

Run the command as is on the worker node.

4. Verify the Cluster:

Back on the master node, check that the worker node has successfully joined:

kubectl get nodes

You should see both the master and worker nodes in the output.

Conclusion:

Congratulations, you’ve now set up a two-node Kubernetes cluster with kubeadm on Ubuntu! With this basic cluster up and running, you can start deploying applications, exploring Kubernetes features, and scaling your infrastructure.

Any queries pls contact us
https://rushiinfotech.in/contact/

Similar Posts

Leave a Reply

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