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:
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curlThese 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.
First, add the Kubernetes APT repository:
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'Update your package list and install the necessary components:
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectlThe 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:
You need to install the containerd package:
sudo apt install -y containerdNext, you'll need to configure containerd by creating a configuration file:
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.tomlOnce that's done, restart the containerd service to apply the changes:
sudo systemctl restart containerdVerify that containerd is running correctly:
sudo systemctl status containerdIf 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:
sudo kubeadm init --container-runtime-endpoint unix:///run/containerd/containerd.sockThis 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:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/configThis 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:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yamlConclusion
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.
