Are you looking to dive into Kubernetes without getting overwhelmed by its complexity? This straightforward guide to installing Kubernetes is your ticket to a fast and easy setup.
This article complements our video tutorial below, which is perfect for beginners and pros alike. It ensures you have all the tools at your fingertips for a seamless installation process.
Understanding Kubernetes
Before proceeding with the installation, let’s briefly discuss Kubernetes. At its core, Kubernetes is a powerful system for managing containerized applications across a cluster of machines.
It’s the go-to for automated scaling, deployment, and management of containerized applications.
requirements
Ensure you’ve got the basics covered by checking out our guides on:
- 3 Linux Ubuntu Server installed;
- SSH access to the machines.
You’re set to proceed with Kubernetes installation.
Step-by-Step Kubernetes Installation
Step 1: Update Your System
Always start with an up-to-date system:
sudo apt update
sudo apt upgrade -y
Step 2: Prepare the System for Kubernetes
- Disable Swap:
Swap needs to be disabled to ensure Kubernetes functions correctly.
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
- Load Kernel Modules:
Enable theoverlay
andbr_netfilter
modules for network functionality.
sudo modprobe overlay
sudo modprobe br_netfilter
- Set System Parameters:
Adjust system settings for Kubernetes networking.
sudo tee /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
# Reload sysctl
sudo sysctl --system
Step 3: Install Container Runtime
Kubernetes requires a container runtime.
- Add Docker’s official GPG key and repository
# Add Docker's official GPG key and repository
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Update package lists after adding Docker repo
sudo apt update
- Install containerd as the container runtime interface for Kubernetes:
sudo apt install -y containerd.io
- Configure containerd and restart
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable containerd
Step 4: Add Kubernetes to Your Repository List
- Import the GPG Key:
sudo apt-get update
sudo apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
- Add Kubernetes Repository:
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
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
Step 5: Install Kubernetes Components
- Update apt and install Kubernetes components (
kubelet
,kubeadm
,kubectl
):
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Step 6: Initialize Your Cluster (JUST on THE Control plane)
Use kubeadm to initialize the cluster:
sudo kubeadm init
Step 7: Create .kube/config file (JUST on THE Control plane)
Use install calico on the cluster:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 8: Install calico (JUST on THE Control plane)
Use install calico on the cluster:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Step 9: Verifying the Installation (JUST on THE Control plane)
To ensure everything is set up correctly:
kubectl cluster-info
STEP 10: JOIN THE KUBERNETES CLUSTERS (JUST ON THE WORKER NODES)
To ensure everything is set up correctly:
kubeadm join 192.168.1.1:6443 --token rez1cv.f65abpcy --discovery-token-ca-cert-hash sha256:dfdab11c03c746cee9a393ad528d22c9aa781b
Step 11: Join The Kubernetes Clusters (JUST on THE CONTROL PLANE)
To ensure everything is set up correctly:
kubectl get nodes -o wide
Wrapping Up
Congratulations! You’ve successfully installed Kubernetes. This guide aims to demystify the process and provide a clear path to getting Kubernetes up and running on your system.
For more in-depth tutorials and tips, check out our posts on:
- Application Monitoring with Docker
- Guide to Deploy Kubernetes
- Monitoring Stack: Prometheus and Grafana
Dive deeper into Kubernetes and container orchestration with our comprehensive video tutorial. It’s designed to complement this guide and offers visual walkthroughs of each step.
Kubernetes allows you to manage containerized applications more efficiently. Whether scaling your application, rolling out updates, or managing your services, Kubernetes provides the tools you need to maintain control.
Start exploring the possibilities today, and transform how you deploy and manage your applications in a containerized environment.
