Kubeadm is a tool you can use to quickly standup a Kubernetes cluster. Here I will show you how to deploy K8S on Ubuntu 22.04. I will use 2 scripts that you can easily understand if you are fairly conversant with Linux batch scripting but if you're not familiar with scripting, just copy and paste!
Let's take note of the following:
Here are the step by step instructions
Step 1: Decide where to install your kubernetes cluster (Public cloud (AWS, AZURE, GCP, Digital Ocean)) or VMs on your laptop etc
Step 2: Provision the VMS and ensure that the networking and firewalls are all configured correctly. The VMs should have at least 2CPUs and 2GB of RAM each. The more the better.
Step 3: Decide on your control node and ensure it has Ubuntu 20.04 or 22.04. Here I used Ubuntu 22.04.
Step 4: Login to the master/control node and become root then run this script
###initialize the system####
sudo swapoff -a
sudo modprobe overlay
sudo modprobe br_netfilter
sudo sysctl -w net.bridge.bridge-nf-call-ip6tables = 1
sudo sysctl -w net.bridge.bridge-nf-call-iptables = 1
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl --system
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
###INSTALL THE CONTAINER RUNTIME-containerd
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
export OS_VERSION=xUbuntu_20.04
export CRIO_VERSION=1.23
curl -fsSL https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS_VERSION/Release.key | sudo gpg --dearmor -o /usr/share/keyrings/libcontainers-archive-keyring.gpg
curl -fsSL https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIO_VERSION/$OS_VERSION/Release.key | sudo gpg --dearmor -o /usr/share/keyrings/libcontainers-crio-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/libcontainers-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS_VERSION/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
echo "deb [signed-by=/usr/share/keyrings/libcontainers-crio-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIO_VERSION/$OS_VERSION/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION.list
sudo apt update
sudo apt install -y cri-o cri-o-runc
sudo systemctl daemon-reload
sudo systemctl enable crio
sudo systemctl start crio
sudo apt install -y containernetworking-plugins
sudo systemctl restart crio
sudo apt install -y cri-tools
###INSTALL KUBERNETES
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
###Initialize the master node
sudo kubeadm init
###Configire the user profile
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
###Install the Calico CNI
curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O
kubectl apply -f calico.yaml
kubectl get pods -n kube-system
Step 5: Wait for the installation to complete successsfully. When all is done, it will spit out a script to use in joing the worker nodes. This will look like:
kubeadm join 192.168.1.147:6443 --token svygw2.vxl9qcg0yzrtqlaj \
--discovery-token-ca-cert-hash sha256:5c8840dfe8a72973790a2259b9838016d742e322f8241a10f97dbcdb3b15ffbe
Something should be wrong if you don't see this so you need to troubleshoot and fix the issue before proceeding.
Remember to keep this script securely stored somewhere because you will need it anytime you want to join a worker node to the master node.
Step 6. If all is well with the master node, you can now start to deploy the worker nodes and join them to the cluster. For each of the nodes, login, become root and run this script:
###initialize the system####
sudo swapoff -a
sudo modprobe overlay
sudo modprobe br_netfilter
sudo sysctl -w net.bridge.bridge-nf-call-ip6tables = 1
sudo sysctl -w net.bridge.bridge-nf-call-iptables = 1
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl --system
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
###INSTALL THE CONTAINER RUNTIME-containerd
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
export OS_VERSION=xUbuntu_20.04
export CRIO_VERSION=1.23
curl -fsSL https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS_VERSION/Release.key | sudo gpg --dearmor -o /usr/share/keyrings/libcontainers-archive-keyring.gpg
curl -fsSL https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIO_VERSION/$OS_VERSION/Release.key | sudo gpg --dearmor -o /usr/share/keyrings/libcontainers-crio-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/libcontainers-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS_VERSION/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
echo "deb [signed-by=/usr/share/keyrings/libcontainers-crio-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIO_VERSION/$OS_VERSION/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION.list
sudo apt update -y
sudo apt install -y cri-o cri-o-runc
sudo systemctl daemon-reload
sudo systemctl enable crio
sudo systemctl start crio
#sudo systemctl status crio
sudo apt install -y containernetworking-plugins
sudo systemctl restart crio
sudo apt install -y cri-tools
###INSTALL KUBERNETES
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-add-repository -y "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update -y
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Step 7: Run the script you obtained from completing the master node
root@master-22-04:~# kubeadm join 192.168.1.147:6443 --token svygw2.vxl9qcg0yzrtqlaj \
--discovery-token-ca-cert-hash sha256:5c8840dfe8a72973790a2259b9838016d742e322f8241a10f97dbcdb3b15ffbe
Step 8: Go to the master node and check that your cluster has all the nodes joined. Here is an example with the above scripts
root@master-22-04:~# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master-22-04 Ready control-plane 22h v1.24.3 192.168.1.147 none> Ubuntu 22.04 LTS 5.15.0-41-generic cri-o://1.23.3
master-22-04-crio Ready <none> 6h53m v1.24.3 192.168.1.148 <none> Ubuntu 22.04 LTS 5.15.0-41-generic cri-o://1.23.3
Step 9: Enjoy your new cluster
Here I have shown you how to deploy a kubernetes cluster with the following services