Set Up a Kubernetes Cluster Using kubeadm – Ubuntu

Kubernetes is an open-source, robust and powerful container orchestration platform that is designed to automate deploying, scaling, as well as operating application containers. It provides a mechanism for automating over clusters of hosts the deployment, scaling, and operation of application containers.

Alright let’s dive into it.

Enabling IPv4 forwarding and allowing iptables to inspect bridged traffic.

Ensure that the br_netfilter, overlay modules are loaded

Ensure that the net.bridge.bridge-nf-call-iptables, net.bridge.bridge-nf-call-ip6tables, and net.ipv4.ip_forward system variables are set to 1 in sysctl config

Installing Container Runtime(containerd)

I chose containerd as my container runtime but you can choose a different one if you want from here

Set up Docker’s apt repository

Install containerd

cgroup Drivers

There are two cgroup drivers available

  • cgroupfs
  • systemd

Identify your system’s cgroup driver with this command

if the output is systemd you have to configure systemd cgroup driver with containerd, but if its not its ok because kubelet uses cgroupfs as default.

Identify the cgroup version

For cgroup v2, the output is cgroup2fs
For cgroup v1, the output is tmpfs

If you use cgroup v2 you’ve to use systemd cgroup driver

Configuring the systemd cgroup driver with containerd

edit /etc/containerd/config.toml and delete all lines and add the following

Save it and restart containerd

Installing kubeadm, kubelet and kubectl

These instructions are for Kubernetes 1.29

Set up kubernetes apt repo

Download the public signing key for the Kubernetes package repositories

Update the apt package index, install kubelet, kubeadm and kubectl

Initializing your control-plane node

--apiserver-advertise-address is the ip address that’s going to be assigned to your control-plane node’s API server and --pod-network-cidr is set mostly 10.244.0.0/16 because it’ll be easy when installing pod network add-ons later.

Then if the installation is successful you should see something like below

To make kubectl work for regular user

Installing pod network add-on(flannel)

Iam choosing flannel as my pod network add-on as it doesn’t require any extra configurations, you can choose different one from here.

You can simply install it using kubectl apply command below

If you are setting up a single machine Kubernetes cluster enter the below command to allow your cluster to schedule pods on control-plane node because by default it won’t

But if you’re setting up a multi node cluster you’ve to ssh into your worker node and enter kubeadm join command you got with the successful installation message on control-plane node.

And if its successful you should see something like this:

Then you can check on control-plane node with kubectl get nodes command. Ensure all of your pods are running with kubectl get pods -a command. And voila you now have a working kubenetes cluster.

The above shown steps are to create a kubernetes cluster with simple configurations, feel free to visit kubernetes official documentation page for more advanced configurations.

Troubleshooting

kube-system pods keeps crashing/sandbox changed error

After running kubeadm init command i saw something like:

So i tried changing the image version and set systemdCgroup to true(we did earlier)

First reset containerd to default configurations

Then locate sandbox_image and SystemdCgroup and update values as below

Then restart containerd for the changes to take effect

And your pods should be running, if not try rebooting computer and that should solve it.

Click here for more info on this error.

We value your input. Share your thoughts or ask questions by leaving a comment.

Umar Arafath

Hey there! I'm Umar Arafath, the face behind unofficialmentor, a passionate Software Engineering undergraduate diving into the IT industry. Even though my formal title may be a student, my heart lies in the field of DevOps. I share my daily learning adventures in this blog so it'll help me remember stuff. It's a win-win end of the day, I reinforce my knowledge, and you learn something new. Please be kind enough to leave a comment! Your feedback fuels my growth. Away from the desk, catch me on the cricket field or badminton court, polishing my physique. I'm also a motorbike enthusiast, who finds riding as a healing spell for my inner peace.

Leave a Reply

Your email address will not be published. Required fields are marked *