Kubernetes Cluster Installation using Kubeadm

Kubernetes Cluster Installation using Kubeadm

Prepare nodes:

We need to add host entries in /etc/hosts in all nodes to make them ping with hostnames

nano /etc/hosts
10.0.0.2      master1.maas  master1
10.0.0.3      worker1.maas  worker1

Now off the SWAP memory of your machines

swapoff -a
  1. Now setup the bridge for IPV4 on all nodes:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# sysctl params required by setup, params persist across reboots
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

# Apply sysctl params without reboot
sudo sysctl --system

2. Now we will install all required packages on all nodes one by one, starting from the master node.

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

3. Download the Google Cloud public signing key:

sudo mkdir /etc/apt/keyrings

sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

4. Add the Kubernetes apt repository:

echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

5. Update apt package index, install kubelet, kubeadm, kubectl and docker.io, and pin their version:

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl docker.io
sudo apt-mark hold kubelet kubeadm kubectl

6. Now initialize kubeadm

kubeadm init --pod-network-cidr=192.168.0.0/16 --ignore-preflight-errors=all

Now run below command on master node

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

7. Setup Calico SDN

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml -O
kubectl create -f custom-resources.yaml

Note if you are using 192.168.0.0/16 then you can proceed with the above command otherwise you need to provide the IPs which were used during, kubeadm init –pod-network-cidr=x.x.x.x/16

Now Setup Workers by running all steps till step 5

Now run the below command on the worker node

kubeadm join 10.0.0.2:6443 --token ndi3ae.ujwfcuais8zm2cyn --discovery-token-ca-cert-hash sha256:fc6c1094159833bf95a3fcb7d49960026e4ddad56f8648b94240cd1c867b2f6b

Now run Kubectl to get no on the master node:

kubectl get no

NAME         STATUS   ROLES           AGE   VERSION

k8s-master   Ready    control-plane   34m   v1.26.3

k8s-worker   Ready    <none>          31m   v1.26.3

kubectl get po -A
NAMESPACE          NAME                                       READY   STATUS    RESTARTS        AGE
calico-apiserver   calico-apiserver-5ffd64dc97-5t5hv          1/1     Running   1 (3m17s ago)   31m
calico-apiserver   calico-apiserver-5ffd64dc97-grdmg          1/1     Running   1 (3m18s ago)   31m
calico-system      calico-kube-controllers-6b7b9c649d-rgdt2   1/1     Running   1 (3m17s ago)   32m
calico-system      calico-node-l8bzk                          1/1     Running   1 (3m17s ago)   32m
calico-system      calico-node-vz27s                          1/1     Running   1 (3m18s ago)   32m
calico-system      calico-typha-85944f6bfb-75zlv              1/1     Running   2 (2m31s ago)   32m
calico-system      csi-node-driver-2fvkb                      2/2     Running   2 (3m17s ago)   31m
calico-system      csi-node-driver-m9r4l                      2/2     Running   2 (3m18s ago)   31m
kube-system        coredns-787d4945fb-9f2rz                   1/1     Running   1 (3m17s ago)   36m
kube-system        coredns-787d4945fb-ngv8f                   1/1     Running   1 (3m17s ago)   36m
kube-system        etcd-k8s-master                            1/1     Running   1 (3m18s ago)   36m
kube-system        kube-apiserver-k8s-master                  1/1     Running   1 (3m18s ago)   36m
kube-system        kube-controller-manager-k8s-master         1/1     Running   1 (3m18s ago)   36m
kube-system        kube-proxy-2rjwc                           1/1     Running   1 (3m18s ago)   36m
kube-system        kube-proxy-gv2z9                           1/1     Running   1 (3m17s ago)   33m
kube-system        kube-scheduler-k8s-master                  1/1     Running   1 (3m18s ago)   36m
tigera-operator    tigera-operator-54b47459dd-bmfbj           1/1     Running   2 (2m29s ago)   32m

 

2 Responses

  1. […] Source: OpenSourceEducation.net By Babar […]

  2. […] Source: OpenSourceEducation.net By Babar […]

Comments are closed.