Installing K8s cluster in your local environment

 Creating a single K8s with kubeadm with Calico Pod Network


The kubeadm tools helps you to setup K8s cluster environment 


Note you have to add hostname/IP in all your virtual machines hosts file to resolve hostname against the ip


e.g vi /etc/hosts


10.10.20.1 masternode

10.10.20.2 workernode1

10.10.20.3      workernode2

the kubeadm tool is a great tool if you need:


1. A simple way for you to try out Kubernetes, possibly for the first time.

2. A way for existing users to automate setting up a cluster and test their application.

3. A building block in other ecosystem and/or installer tools with a larger scope.


To setup a K8s cluster you need 3 instances one for master and 2 for workernodes


check required ports

MasterNodes

Protocol Direction    Port    Range      Purpose        Used By


TCP       Inbound     6443* Kubernetes API server       All


TCP       Inbound   2379-2380 etcd server client API  kube-apiserver, etcd


TCP       Inbound     10250     Kubelet API            Self, Control plane


TCP       Inbound     10251     kube-scheduler           Self


TCP       Inbound     10252   kube-controller-manager     Self


Wroker nodes


TCP     Inbound       10250 kubelet API        Self, Control plane


TCP Inbound       30000-32767 NodePortService    ALL



Installing runtime


 


By default, Kubernetes uses the Container Runtime Interface (CRI) to interface with your chosen container runtime.


If you don't specify a runtime, kubeadm automatically tries to detect an installed container runtime by scanning through a list of well known Unix domain sockets.


Runtime


Path to Unix domain socket


Docker


/var/run/docker.sock


containerd


/run/containerd/containerd.sock


CRI-O


/var/run/crio/crio.sock



If both Docker and containerd are detected, Docker takes precedence. This is needed because Docker 18.09 ships with containerd and both are detectable even if you only installed Docker. If any other two or more runtimes are detected, kubeadm exits with an error.


Installation on Ubuntu (Both on Master and Worker Nodes)


sudo apt-get install -y apt-transport-https ca-certificates curl gpg




mkdir /etc/apt/keyrings/




curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg


echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl


Create Master Server

On master machine run the below command

1.  kubeadm init --apiserver-advertise-address=<<Master ServerIP>> --pod-network-cidr=192.168.0.0/16

2.  mkdir -p $HOME/.kube

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

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

5. Run the join command on workernodes to connect these on kubernetes cluster.

Install Calico (run it only on master node)

# kubectl create -f https://docs.projectcalico.org/v3.18/manifests/calico.yaml

kubectl get nodes

Wait for above command and run again it may take a minute or so to get all the nodes in ready state.

Installation on RHEL/CentOS (Both on Master and Worker Nodes)

In case if you are using CentOS/RHEL

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

repo_gpgcheck=1

gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg \

   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

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

sudo systemctl enable --now kubelet

 




Comments

Popular posts from this blog

How To Enable SSH Login for root user in RHEL9/CENTOS9

How to Add Users/Group/OU in OpenLdap

HOW TO INSTALL AND CONFIGURE KEEPALIVE BETWEEN TWO SERVERS ON CENTOS/RHEL

USEFULL COMMANDS TO MANAGE ZIMBRA USERS AND SERVICES

File Permissions in Linux

HOW TO INSTALL AND CONFIGURE HAPROXY ON RHEL/CENTOS