Installation and Setup of the Kubernetes Cluster

Installation and Setup of the Kubernetes Cluster

For Kubernetes installation, we need at least 2 nodes/ec2-instances/servers. One for the control plane/master node which requires a minimum 2 CPUs and 4GB RAM and another one for the worker node.

For practice we can have a single node cluster, it is possible using Minikube. so in this article, we are going to see the installation using Kubeadm and Minikube.

A] Kubeadm:

Machine Specifications:

  1. Image - Amazon Linux 2

  2. Instance Type - t2.medium

commands to run on the master nodes as well as on the worker node.

First, we need a container runtime on both nodes. we are installing the docker

$ sudo yum update -y
$ sudo yum install docker -y
$ sudo systemctl start docker
$ sudo systemctl enable docker

//check the status of docker
$ sudo systemctl status docker

Now run the following command to create a file and write the specified information in the file.

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
//Set SELinux in permissive mode (effectively disabling it)
$ sudo setenforce 0

$ sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

Now it's time to install Kubeadm, Kubelet and Kubectl.

$ sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

// Enable kubelet
$ sudo systemctl enable --now kubelet

After this run the following commands only on the master node

// initialize kubeadm
$ kubeadm init

In the output of the above commands, we will have the commands to run on the master and the joining command to run on the worker nodes

// master node commands
// commands to run as 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

// commands to run as root user
$ export KUBECONFIG=/etc/kubernetes/admin.conf

For Kubernetes Container Network Interface ( CNI ) we are installing Calico which acts as a plugin which provides networking for pods and containers.

NOTE: Install CNI before running the joining command

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

$ kubectl apply -f calico.yaml

// If you want generate new joining command
$ kubeadm token create --print-join-command

B] Minikube:

I'm installing Minikube on the local machine which is Ubuntu 22.04 have 2 CPUs and 4GB RAM.

First, we need docker or any other container runtime. but lets install docker.

$ sudo apt-get update -y
$ sudo apt-get install docker.io -y
$ sudo systemctl start docker
$ sudo systemctl enable docker

//check the status of docker
$ sudo systemctl status docker

// change permissions of the docker.sock
sudo chmod 666 /var/run/docker.sock

Install Minikube dependencies

$ sudo apt install -y curl wget apt-transport-https

Now its time to download minikube binary and copy binary to /usr/local/bin

$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

$ sudo install minikube-linux-amd64 /usr/local/bin/minikube

To verify minikube installation

$ minikube version

Install kubernetes command line tool kubectl

$ curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

// give executable permissions and move to /usr/local/bin
$ chmod +x kubectl
$ sudo mv kubectl /usr/local/bin/

//verify kubectl installation
$ kubectl version

Finally start minikube using docker as a driver

$ minikube start --driver=docker

Conclusion:

We have learned to install and setup kubernetes cluster using kubeadm and single node cluster using minikube.

Thank you!!!

Did you find this article valuable?

Support Pranav Thorve by becoming a sponsor. Any amount is appreciated!