How to install Kubernetes on Ubuntu 24.04
This guide installs a standalone Kubernetes control plane on Ubuntu 24.04 using the official kubeadm tool. Follow the steps to set up the cluster, join worker nodes, and verify the API server is running.
You will install a standalone Kubernetes control plane on a single Ubuntu 24.04 server. These steps target Ubuntu 24.04 LTS and install Kubernetes version 1.29.x. You will configure the API server, etcd, kubelet, and a container runtime before adding worker nodes.
Prerequisites
- Operating System: Ubuntu 24.04 LTS (Noble Numbat) with at least 4GB RAM.
- Privileges: Root access or ability to use
sudo. - Network: Static IP address configured and firewall ports 6443, 10250, 2379-2380, and 10255 open.
- Dependencies: Docker 27.x or containerd 1.7.x installed.
Step 1: Update system packages and install dependencies
Update the package index to ensure you install the latest security patches. Then install the necessary build dependencies, including the container runtime and kubernetes packages.
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
Expected output shows packages being downloaded and installed:
Get:1 http://security.ubuntu.com/ubuntu noble-security InRelease [125 kB]
Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease
...
Setting up libcurl4t64:amd64 (8.5.0-1ubuntu10.5) ...
Processing triggers for libc-bin (2.39-0ubuntu8.9) ...
Step 2: Install containerd
Kubernetes uses containerd as its default container runtime. Download the containerd package from the official Ubuntu repositories and install it.
curl -LO https://github.com/containerd/containerd/releases/download/v1.7.20/containerd-1.7.20-linux-amd64.tar.gz
sudo tar -C /usr/local/bin -xzf containerd-1.7.20-linux-amd64.tar.gz
rm containerd-1.7.20-linux-amd64.tar.gz
Verify the installation with this command:
containerd --version
You will see output like: containerd version 1.7.20.
Edit the systemd service file to enable the runtime:
sudo systemctl enable --now containerd
Step 3: Add the Kubernetes GPG key and repository
Add the official Kubernetes public signing key and the Ubuntu repository to your system. This ensures you download the correct binaries for your architecture.
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/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.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Update the package index again to recognize the new source:
sudo apt update
Step 4: Install Kubernetes components
Install the control plane binaries (kubelet, kubeadm, kubectl) and the container runtime. This command pulls the specific versions compatible with Ubuntu 24.04.
sudo apt install -y kubelet kubeadm kubectl
Expected output confirms the installation:
Setting up kubelet (1.29.7-1.1.1) ...
Setting up kubeadm (1.29.7-1.1.1) ...
Setting up kubectl (1.29.7-1.1.1) ...
Set the correct version for the kubelet service:
sudo apt-mark hold kubelet
Start the kubelet service immediately:
sudo systemctl enable --now kubelet
Step 5: Initialize the control plane node
Run the kubeadm init command to set up the control plane. This creates the API server, etcd cluster, and kube-proxy. Replace <node-ip> with your actual server IP address.
kubeadm init --pod-network-cidr=10.244.0.0/16 --cri-socket=/run/containerd/containerd.sock
The command outputs a series of steps and ends with a configuration block. Copy the kubectl command at the bottom of the output to configure your local kubeconfig file:
kubectl apply -k "https://k8s.io/manifests/pod-security-policies/default"
Apply the network plugin configuration to enable pod communication:
kubeadm init phase kubeproxy join --config /etc/kubernetes/manifests/kubeadm-config.yaml
Verify the installation
Check the status of all Kubernetes components to ensure the cluster is healthy. Run the following command to see the API server, etcd, and kubelet status.
kubeadm init phase components status
Expected output shows all components as Running:
component: apiserver
status: Running
component: etcd
status: Running
component: kubelet
status: Running
Verify the API server is listening on port 6443:
sudo netstat -tlnp | grep 6443
You should see output like: tcp6 0 0 0.0.0.0:6443 0.0.0.0:* LISTEN 1234/kube-apiserver.
Troubleshooting
If the API server fails to start, check the kubelet service logs for errors. Use this command to inspect the logs:
journalctl -u kubelet -f
Look for messages indicating missing certificates or port conflicts. Ensure the firewall allows traffic on port 6443:
sudo ufw allow 6443/tcp
If the etcd cluster is unhealthy, verify the etcd service is running:
sudo systemctl status etcd
Restart the kubelet service if it is stuck:
sudo systemctl restart kubelet
Reset the cluster if necessary by running kubeadm reset and repeating the initialization steps.