Skip to content

Instantly share code, notes, and snippets.

@NotHarshhaa
Last active November 26, 2025 11:59
Show Gist options
  • Select an option

  • Save NotHarshhaa/854ed5c12fff07acde88faf95b9decff to your computer and use it in GitHub Desktop.

Select an option

Save NotHarshhaa/854ed5c12fff07acde88faf95b9decff to your computer and use it in GitHub Desktop.
Kubernetes (k8s) step-by-step installation guide on Ubuntu 20.04/22.04/24.04 from scratch [2025 Latest]

banner

🧩 Kubernetes Installation Guide (2025 Update)

By H A R S H H A A


Step 1: Update Your System

Update the package list and upgrade installed packages:

sudo apt update && sudo apt upgrade -y
sudo reboot

Step 2: Install Dependencies

Install required tools and packages:

sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release

Step 3: Disable Swap

Kubernetes requires swap to be disabled:

sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab

Step 4: Install Docker or containerd

Kubernetes needs a container runtime. We'll use containerd (recommended).

4.1: Install containerd

sudo apt install -y containerd

4.2: Configure containerd

Generate the default configuration file:

sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml

Restart containerd:

sudo systemctl restart containerd
sudo systemctl enable containerd

Step 5: Install Kubernetes Components

Install kubeadm, kubelet, and kubectl.

⚠️ Note

The old repository (https://apt.kubernetes.io kubernetes-xenial) is deprecated. Use the new pkgs.k8s.io repository instead.

5.1: Add the Kubernetes APT Repository (New Method)

# Create a keyring directory
sudo mkdir -p /etc/apt/keyrings

# Download and add the Kubernetes repository GPG key
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | \
  sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

# Add the Kubernetes repository
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] \
https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /" | \
sudo tee /etc/apt/sources.list.d/kubernetes.list

# Update package list
sudo apt update

💡 If a newer version (like v1.31) is available, replace v1.30 in the URL above.

5.2: Install kubeadm, kubelet, and kubectl

sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

If you see errors about Snap versions, remove them first:

sudo snap remove kubelet kubectl kubeadm

Step 6: Initialize the Kubernetes Cluster

Run the following command on the control-plane (master) node:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

6.1: Configure kubectl for the Current User

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

6.2: Save the Join Command

The output of kubeadm init will include a kubeadm join command for worker nodes. Copy and save this for later.


Step 7: Install a Pod Network Add-On

Choose a CNI (Container Network Interface). We'll use Calico.

7.1: Apply the Calico Manifest

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Step 8: Add Worker Nodes

Run the kubeadm join command from Step 6.2 on each worker node:

sudo kubeadm join <master-ip>:6443 --token <token> \
    --discovery-token-ca-cert-hash sha256:<hash>

Step 9: Verify the Cluster

9.1: Check Nodes

On the master node, check the status of nodes:

kubectl get nodes

9.2: Check Pods

Verify that the cluster is working by checking pods in the kube-system namespace:

kubectl get pods -n kube-system

Optional: Enable Autocompletion for kubectl

sudo apt install -y bash-completion
echo 'source <(kubectl completion bash)' >>~/.bashrc
source ~/.bashrc

Troubleshooting Tips

1. Reset the Cluster

If the installation fails, reset kubeadm and try again:

sudo kubeadm reset -f
sudo rm -rf $HOME/.kube

2. Check Logs

Use the following commands to troubleshoot issues:

journalctl -xeu kubelet
kubectl describe pod <pod-name> -n kube-system

This guide is now compatible with modern Ubuntu (20.04, 22.04, 24.04) and Kubernetes v1.30+ repositories.

@NotHarshhaa
Copy link
Author

🧾 Changelog – Kubernetes Install Guide (2025 Update)

Date: October 2025
Author: @NotHarshhaa


🔧 Fixes

  • 🛠️ Fixed Step 5 – Replaced deprecated Kubernetes APT repo (https://apt.kubernetes.io kubernetes-xenial) with the new official repo:

    https://pkgs.k8s.io/core:/stable:/v1.30/deb/
    
  • 🗝️ Removed apt-key usage (deprecated in Ubuntu 22.04+); added new GPG keyring method using /etc/apt/keyrings/kubernetes-apt-keyring.gpg.

  • 🚫 Resolved “no Release file” error during sudo apt update.

  • 🧹 Added fix for Snap conflicts (removed snap versions of kubeadm, kubelet, kubectl before apt install).


💡 Improvements

  • ✅ Updated comments and version hints for v1.30+ Kubernetes releases.
  • 💬 Clarified that the repo URL can be updated to future versions (e.g., v1.31).
  • 🧱 Improved formatting and Markdown structure for better readability.
  • 🔒 Added sudo apt-mark hold step to prevent unintended auto-upgrades.

🧠 Notes

  • The guide now works correctly on Ubuntu 20.04, 22.04, and 24.04.
  • Verified for containerd runtime and Calico networking setup.
  • Fully compliant with Kubernetes’ latest APT packaging and GPG standards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment