Learn how to install Kubernetes on Ubuntu 24.04 with this detailed step-by-step guide. From setting up Docker and disabling swap to initializing the master node and joining worker nodes, this guide covers everything you need to build a functional Kubernetes cluster on your Ubuntu server.
8 min
Edited:06-10-2024
Kubernetes (K8s) is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. In this guide, we'll walk through the steps to install Kubernetes on Ubuntu 24.04.
Before you begin, ensure you have the following:
Ubuntu 24.04 server installed.
At least 2 CPUs and 2GB of RAM (for the master node).
A static IP address for each node (master and worker nodes).
Docker installed on your server.
You can install Docker following this guide
And here is a summary on how to install Docker:
Update package lists:
1. sudo apt update
Install dependencies:
1. sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add Docker’s official GPG key:
1. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Add Docker APT repository:
1. echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Enable and start Docker:
1. sudo systemctl enable docker
2. sudo systemctl start docker
Verify Docker installation:
1. docker --version
Kubernetes requires swap to be disabled for optimal performance.
Turn off swap:
1. sudo swapoff -a
Having swap available on a system reduces predictability. Swap's performance is worse than regular memory, sometimes by many orders of magnitude, which can cause unexpected performance regressions. Furthermore, swap changes a system's behaviour under memory pressure
You can disable swap permanently by editing /etc/fstab:
1. sudo nano /etc/fstab
Find the line that refers to swap and comment it out by adding # at the beginning.
Kubernetes consists of several components. We'll install kubeadm, kubelet, and kubectl.
1- Add Kubernetes repository:
1. sudo apt update
2. sudo apt install -y apt-transport-https ca-certificates curl
3. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
4. echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
2- Update the package list and install Kubernetes:
1. sudo apt update
2. sudo apt install -y kubelet kubeadm kubectl
3- Hold the versions to prevent auto-updates:
1. sudo apt-mark hold kubelet kubeadm kubectl
1- Initialize the cluster (replace <your-cidr> with the appropriate network CIDR, usually 192.168.0.0/16):
1. sudo kubeadm init --pod-network-cidr=<your-cidr>
After initialization, you'll see a message with commands to configure your user and install a network plugin. Take note of the kubeadm join command, as you'll use it to add worker nodes to the cluster.
2- Set up kubeconfig for the admin user:
1. mkdir -p $HOME/.kube
2. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
3. sudo chown $(id -u):$(id -g) $HOME/.kube/config
Kubernetes requires a network plugin to manage inter-pod communications. Here, we'll install Calico, a widely-used network plugin.
1- Install Calico:
1. kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
2- Verify the installation:
1. kubectl get pods --all-namespaces
For each worker node:
1- Run the kubeadm join command generated during the master node initialization:
1. sudo kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Replace <master-ip>, <token>, and <hash> with the actual values from the master node setup.
Verify that the nodes have joined: On the master node, run:
1. kubectl get nodes
You should see both the master and worker nodes listed.
Once the installation is complete, Check the status of nodes:
1. kubectl get nodes
All nodes should be in the Ready state.
Check the status of system pods:
1. kubectl get pods --all-namespaces
All essential Kubernetes pods should be running.
You now have a fully functional Kubernetes cluster running on Ubuntu 24.04! From here, you can start deploying your containerized applications, setting up services, and scaling your applications with ease.
14-10-2024
This article offers a detailed guide on installing and configuring IPTables on an Ubuntu VPS. IPTables is a powerful firewall tool that helps secure your server by controlling inbound and outbound traffic. Learn how to set up rules for traffic filtering, configure basic security policies, and apply custom rules to protect your VPS.
IPtables
security
12 min
This article offers a comprehensive guide on installing and configuring ModSecurity, a powerful web application firewall (WAF), on an Ubuntu VPS. Learn how to secure your server by filtering and monitoring HTTP requests, set up ModSecurity with Nginx or Apache, and apply rules to protect against common web attacks.
Modsecurity
security
10 min
14-10-2024
This article provides a comprehensive guide on installing and configuring PHP-FPM (FastCGI Process Manager) on an Ubuntu VPS. Learn how to optimize PHP performance for your web applications by configuring PHP-FPM with Nginx or Apache, managing pools, and fine-tuning settings for efficient processing of PHP scripts.
PHP-FPM
speed
optimise
12 min