All articles
Article 3 min read

Setting Up a Kubernetes Node on Ubuntu 24.04 Using containerd

Discover how to install and configure Kubernetes on Ubuntu 24.04 using containerd, a popular lightweight container runtime that is fully compatible with Docker.

Introduction

Kubernetes has become the go-to orchestration platform for managing containerized applications in production environments. As organizations increasingly adopt cloud-native technologies, many are looking for efficient and effective ways to deploy Kubernetes clusters. With Ubuntu emerging as a favored operating system for both development and production, setting up a Kubernetes node using containerd offers a streamlined approach. In this guide, we will walk you through the installation and configuration process for setting up a Kubernetes node on Ubuntu 24.04, utilizing containerd as the container runtime.

Prerequisites

Before starting, make sure to have the following prerequisites in place:

A machine running Ubuntu 24.04 (you can use a virtual machine, cloud instance, or physical server).

A user account with sudo privileges.

Basic knowledge of terminal commands and Linux system administration.

Step 1: Install Required Packages

Start by updating your package lists and installing necessary packages. Open your terminal and execute:

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

These commands ensure that your system can handle HTTPS traffic and securely install packages.

Step 2: Install Kubernetes Components

Next, we need to install kubectl, kubeadm, and kubelet. These three components are essential for managing and operating a Kubernetes cluster.

1.

First, add the Kubernetes APT repository:

bash
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo bash -c 'echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list'
2.

Update your package list and install the necessary components:

bash
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

The hold command prevents these packages from being automatically updated, which can be crucial for system stability.

Step 3: Install containerd

Containerd serves as a lightweight container runtime that's compliant with Docker. To install it:

1.

You need to install the containerd package:

bash
sudo apt install -y containerd
2.

Next, you'll need to configure containerd by creating a configuration file:

bash
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
3.

Once that's done, restart the containerd service to apply the changes:

bash
sudo systemctl restart containerd
4.

Verify that containerd is running correctly:

bash
sudo systemctl status containerd

If everything is set up correctly, you should see the service status as active (running).

Step 4: Initialize the Kubernetes Cluster

Now that the required components are installed, you will begin the cluster initialization process. Run the following command to initialize your Kubernetes cluster:

bash
sudo kubeadm init --container-runtime-endpoint unix:///run/containerd/containerd.sock

This command initializes the cluster and specifies the containerd socket. Following this, you should see output detailing the next steps, including how to set up kubectl access.

Step 5: Configure kubectl Access

To manage your Kubernetes cluster more easily, you will want to configure kubectl for your user account. Execute the following commands:

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

This setup allows you to run kubectl commands without needing to use sudo.

Step 6: Deploy a Network Add-on

At this point, your Kubernetes node is up and running, but it requires a network add-on for inter-pod communication. You can choose from various Kubernetes networking solutions, such as Calico or Flannel. For this example, we'll install Calico:

bash
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Conclusion

Congratulations! You have successfully set up a Kubernetes node on Ubuntu 24.04 using containerd as the container runtime. This configuration provides a lightweight and efficient approach to managing your containerized applications. From here, you can begin deploying workloads, experimenting with Kubernetes features, and scaling your applications. Consider exploring additional resources, best practices, and advanced configurations to maximize your use of Kubernetes in your production environment.