Bobcares

Install and Configure Kubernetes on Ubuntu 24.04

PDF Header PDF Footer

Learn how to install and configure Kubernetes on Ubuntu 24.04. Our Kubernetes Support team is here to answer queries and concerns.

Install and Configure Kubernetes on Ubuntu 24.04

Kubernetes has become the go-to container orchestration platform for managing scalable and resilient applications. If you’re planning to deploy Kubernetes on Ubuntu 24.04, our Experts are here to help.

Whether you’re setting up a multi-node cluster or encountering errors like Kubernetes 429 Too Many Requests, expert assistance can make all the difference.

This blog will walk you through all the steps, from preparing your nodes to launching your first application.

Prerequisites

Before we begin, make sure the setup meets the following requirements:

  • Ubuntu 24.04 installed on all nodes (both master and workers)
  • SSH access is enabled on all instances
  • A regular user account with `sudo` privileges
  • At least 2GB RAM, 2 CPUs, and 20GB of free disk space per node
  • Reliable internet connection

If you’re working with a single-node setup, you might also want to explore our guide on installing Kubernetes on Ubuntu 22.04 single node.

Step 1. Configure Hostnames and `/etc/hosts` File

  1. To enable smooth communication within the cluster, update the `/etc/hosts` file on all nodes:
    sudo nano /etc/hostsCopy Code
  2. Then, add entries for all nodes:
    master-ip    k8s-master-node
    worker1-ip   k8s-worker-node-1
    worker2-ip   k8s-worker-node-2
    Copy Code
  3. Now, set the hostname on each node:
    
    # On master node
    sudo hostnamectl set-hostname "k8s-master-node"
    # On worker 1
    sudo hostnamectl set-hostname "k8s-worker-node-1"
    # On worker 2
    sudo hostnamectl set-hostname "k8s-worker-node-2"
    # Apply changes
    exec bash
    Copy Code
  4. Next, confirm hostname:
    hostnameCopy Code
  5. Then, verify inter-node connectivity:
    ping -c 3 k8s-worker-node-1
    ping -c 3 k8s-worker-node-2
    Copy Code

Step 2. Disable Swap

Kubernetes requires swap to be disabled for performance consistency.

sudo swapoff -aCopy Code

To make this change permanent:

sudo nano /etc/fstab
# Comment out the swap line by adding a # at the beginning
Copy Code

To confirm the swap is off:


swapon --show
# No output means swap is disabled
Copy Code

Step 3. Load Required Kernel Modules

Enable kernel modules for containerd:


sudo modprobe overlay
sudo modprobe br_netfilter
Copy Code

Then, persist the settings:


sudo tee /etc/modules-load.d/k8s.conf <<EOF
overlay
br_netfilter
EOF
Copy Code

Step 4. Configure Kubernetes Networking

Now, enable the required sysctl parameters:

sudo nano /etc/sysctl.d/k8s.confCopy Code

Then, add:


net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
Copy Code

Now, apply the settings:

sudo sysctl –systemCopy Code

Step 5. Install Docker

  1. Install Docker from Ubuntu repositories:
    
    sudo apt update
    sudo apt install docker.io -y
    Copy Code
  2. Next, enable Docker to start on boot:
    
    sudo systemctl enable docker
    sudo systemctl start docker
    Copy Code
  3. Then, configure containerd:
    
    sudo mkdir /etc/containerd
    sudo sh -c "containerd config default > /etc/containerd/config.toml"
    sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
    sudo systemctl restart containerd
    Copy Code

Step 6. Install Kubernetes Components

  1. To install dependencies:
    sudo apt-get install curl ca-certificates apt-transport-https -yCopy Code
  2. Then, add the Kubernetes GPG key and repository:
    curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/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.31/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    sudo apt update
    Copy Code
  3. To install Kubernetes tools:
    sudo apt install kubelet kubeadm kubectl -yCopy Code

Step 7. Initialize the Kubernetes Cluster (Master Node Only)

To initialize the Kubernetes cluster, run this command:

sudo kubeadm init –pod-network-cidr=10.10.0.0/16Copy Code

After initialization, configure `kubectl`:


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

If the cluster fails to initialize, errors such as Kubernetes Backoff Limit Exceeded may occur and will require further troubleshooting.

Step 8. Install Calico Network Plugin

  1. To install Calico Operator:
    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/tigera-operator.yaml
    Copy Code
  2. Then, download and modify the custom resources:
    curl -O https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/custom-resources.yaml
    sed -i 's/cidr: 192.168.0.0/16/cidr: 10.10.0.0/16/g' custom-resources.yaml
    kubectl create -f custom-resources.yaml
    Copy Code
  3. Then, verify:
    kubectl get nodesCopy Code

Step 9. Join Worker Nodes to the Cluster

We can use the `kubeadm join` command from the output of the `kubeadm init` step on each worker node:

kubeadm join :6443 --token
--discovery-token-ca-cert-hash sha256:
Copy Code

To verify the cluster:

kubectl get nodesCopy Code

If any node fails to join and stays in a pending state, refer to our troubleshooting guide for Kubernetes Timed Out Waiting for the Condition.

Step 10. Test Your Kubernetes Cluster

  1. First, create a namespace:
    kubectl create namespace demo-namespaceCopy Code
  2. Then, deploy Nginx:
    kubectl create deployment my-app --image=nginx --replicas=2namespace=demo-namespaceCopy Code
  3. Next, expose using NodePort:
    kubectl expose deployment my-app -n demo-namespace --type NodePort --port 80Copy Code
  4. To get service details:
    kubectl get svc -n demo-namespaceCopy Code
  5. Then, test using `curl`:
    curl http://worker-node-ip:node-portCopy Code

We will receive a standard Nginx HTML page.

Bonus Tip: Install Kubectl Using Snap

If we prefer installing `kubectl` via Snap:


sudo apt install snapd -y
sudo snap install kubectl --classic
kubectl version --client
Copy Code

To uninstall:

sudo snap remove kubectlCopy Code

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to install and configure Kubernetes on Ubuntu 24.04.

0 Comments

Submit a Comment

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

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!