K8s Labs 001 Building a Kubernetes Cluster With Kubeadm

K8s Labs 001 Building a Kubernetes Cluster With Kubeadm

Post Date : 2024-04-20T12:08:31+07:00

Modified Date : 2024-04-20T12:08:31+07:00

Category: devops

Tags: k8s , kubenertes

Forehead

This lab will allow you to practice the process of building a new Kubernetes cluster. You will be given a set of Linux servers, and you will have the opportunity to turn these servers into a functioning Kubernetes cluster. This will help you build the skills necessary to create your own Kubernetes clusters in the real world.

image

Steps

image

Details

ssh cloud_user@35.173.219.74
8]J9MUmn

ssh cloud_user@34.228.230.195
8]J9MUmn

ssh cloud_user@54.164.162.1
8]J9MUmn
cloud_user@k8s-control:~$ cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
> overlay
> br_netfilter
> EOF
cloud_user@k8s-control:~$ sudo modprobe overlay
cloud_user@k8s-control:~$ cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
> net.bridge.bridge-nf-call-iptables = 1
> net.ipv4.ip_forward = 1
> net.bridge.bridge-nf-call-ip6tables = 1
> EOF
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1

apply system setting immediately

sudo sysctl --system

install containerd

sudo apt-get update && sudo apt-get install -y containerd

create container d config

sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl status containerd

image

install kubelet and kubeadm

sudo apt-get install -y apt-transport-https ca-certificates curl gpg
sudo swapoff -a
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/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.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt-get install -y kubelet kubeadm kubectl
# prevent automatically update
sudo apt-mark hold kubelet kubeadm kubectl

Repeat the process of installing containerd kubelet kubeadm kubectl in your worker nodes.

Initialize the cluster

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

setup kubectl config

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

Install the Calico Network Add-On

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml\
kubectl get nodes -o wide
kubectl get pods --namespace=kube-system

Join the Worker Nodes to the Cluster

sudo kubeadm token list
sudo kubeadm token create --print-join-command
sudo kubeadm token delete <token>

# run this command in your worker node
sudo kubeadm join 10.0.1.101:6443 --token ibe7u6.s8zpv2vzjvlds4tg --discovery-token-ca-cert-hash sha256:f63fcb124326b47cba0e6c382e6bf783cb187491c57ecd470364beec9e0f84be
8]J9MUmn
kubectl get nodes

image

Terminologies

  1. containerd

image

Reference

You may got this error, if follow the old way to install kubeadm on ubuntu Ubuntu kubernetes-xenial package repository issue

Linux Commands

ls > file # write stdin to file
ls | tee file # write stdin to file and stdout(screen)
cloud_user@k8s-control:~$ cat <<EOF
> Hello
> World!
> echo $HOME
> EOF
Hello
World!
echo /home/cloud_user
cloud_user@k8s-control:~$