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.
An Overview:
Prerequisites
- Step 1. Configure Hostnames and `/etc/hosts` File
- Step 2. Disable Swap
- Step 3. Load Required Kernel Modules
- Step 4. Configure Kubernetes Networking
- Step 5. Install Docker
- Step 6. Install Kubernetes Components
- Step 7. Initialize the Kubernetes Cluster (Master Node Only)
- Step 8. Install Calico Network Plugin
- Step 9. Join Worker Nodes to the Cluster
- Step 10. Test Your Kubernetes Cluster
- Bonus Tip: Install Kubectl Using Snap
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
- To enable smooth communication within the cluster, update the `/etc/hosts` file on all nodes:
sudo nano /etc/hosts
- Then, add entries for all nodes:
master-ip k8s-master-node
worker1-ip k8s-worker-node-1
worker2-ip k8s-worker-node-2
- 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
- Next, confirm hostname:
hostname
- Then, verify inter-node connectivity:
ping -c 3 k8s-worker-node-1
ping -c 3 k8s-worker-node-2
Step 2. Disable Swap
Kubernetes requires swap to be disabled for performance consistency.
sudo swapoff -a
To make this change permanent:
sudo nano /etc/fstab
# Comment out the swap line by adding a # at the beginning
To confirm the swap is off:
swapon --show
# No output means swap is disabled
Step 3. Load Required Kernel Modules
Enable kernel modules for containerd:
sudo modprobe overlay
sudo modprobe br_netfilter
Then, persist the settings:
sudo tee /etc/modules-load.d/k8s.conf <<EOF
overlay
br_netfilter
EOF
Step 4. Configure Kubernetes Networking
Now, enable the required sysctl parameters:
sudo nano /etc/sysctl.d/k8s.conf
Then, add:
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
Now, apply the settings:
sudo sysctl –system
Step 5. Install Docker
- Install Docker from Ubuntu repositories:
sudo apt update
sudo apt install docker.io -y
- Next, enable Docker to start on boot:
sudo systemctl enable docker
sudo systemctl start docker
- 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
Step 6. Install Kubernetes Components
- To install dependencies:
sudo apt-get install curl ca-certificates apt-transport-https -y
- 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
- To install Kubernetes tools:
sudo apt install kubelet kubeadm kubectl -y
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/16
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
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
- To install Calico Operator:
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/tigera-operator.yaml
- 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
- Then, verify:
kubectl get nodes
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:
To verify the cluster:
kubectl get nodes
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
- First, create a namespace:
kubectl create namespace demo-namespace
- Then, deploy Nginx:
kubectl create deployment my-app --image=nginx --replicas=2 –namespace=demo-namespace
- Next, expose using NodePort:
kubectl expose deployment my-app -n demo-namespace --type NodePort --port 80
- To get service details:
kubectl get svc -n demo-namespace
- Then, test using `curl`:
curl http://worker-node-ip:node-port
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
To uninstall:
sudo snap remove kubectl
[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