Kubernetes is a powerful container orchestration platform that helps you manage containerized applications across a cluster of machines. In this guide, we will walk you through the steps to set up a Kubernetes cluster using Kubeadm on Ubuntu 22.04. Whether you are deploying it on a local server or using a Windows VPS UK, this tutorial provides all the necessary steps.
Step 1: Update Your System
Before installing Kubernetes, make sure your system is up to date. Run the following commands:
sudo apt update && sudo apt upgrade -y
Keeping your system updated is crucial for security and performance, whether you're setting it up locally or on a VPS Windows Servers platform.
Step 2: Install Required Packages
Install required packages and dependencies for Kubernetes:
sudo apt install -y apt-transport-https ca-certificates curl
Step 3: Disable Swap
Kubernetes requires swap to be disabled. Disable it using the following command:
sudo swapoff -a
To make this change permanent, edit the /etc/fstab
file and comment out any swap entries:
sudo nano /etc/fstab
Step 4: Add Kubernetes Repository
Add the Kubernetes APT repository to your system:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
Step 5: Install Kubeadm, Kubelet, and Kubectl
Install Kubeadm, Kubelet, and Kubectl using the following commands:
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
Enable and start the Kubelet service:
sudo systemctl enable kubelet
sudo systemctl start kubelet
Step 6: Initialize the Kubernetes Cluster
To initialize the Kubernetes master node, run the following command:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
After the initialization is complete, follow the instructions provided in the terminal to set up your kubeconfig file:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 7: Install a Pod Network Add-on
You need to install a network add-on to allow communication between the pods. For example, to install Calico, run the following command:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Step 8: Join Worker Nodes to the Cluster
If you have additional nodes to join to the cluster, you will need to run the command provided at the end of the kubeadm init
output on each worker node. It will look something like this:
kubeadm join :6443 --token --discovery-token-ca-cert-hash sha256:
Step 9: Verify the Cluster
To check the status of your Kubernetes cluster, use the following command:
kubectl get nodes
You should see your master and any joined worker nodes listed as "Ready."