Update the package list and upgrade installed packages:
sudo apt update && sudo apt upgrade -y
sudo reboot
Install required tools and packages:
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
Kubernetes requires swap to be disabled:
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab
Kubernetes needs a container runtime. We'll use containerd (recommended).
sudo apt install -y 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
Install kubeadm, kubelet, and kubectl.
curl -fsSL 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
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Run the following command on the master node:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
The output of kubeadm init
will include a kubeadm join
command for worker nodes. Save this for later.
Choose a CNI (Container Network Interface). We'll use Calico.
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
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>
On the master node, check the status of nodes:
kubectl get nodes
Verify that the cluster is working by checking pods in the kube-system
namespace:
kubectl get pods -n kube-system
sudo apt install -y bash-completion
echo 'source <(kubectl completion bash)' >>~/.bashrc
source ~/.bashrc
-
Reset the Cluster
If the installation fails, reset kubeadm and try again:sudo kubeadm reset -f sudo rm -rf $HOME/.kube
-
Check Logs
Use the following commands to troubleshoot issues:journalctl -xeu kubelet kubectl describe pod <pod-name> -n kube-system
This guide provides a basic Kubernetes cluster installation. For production, consider high-availability setups, security configurations, and monitoring tools. Let me know if you'd like additional details!
Starting from Kubernetes v1.20, Docker support through the dockershim was deprecated, and as of v1.24, it has been completely removed. This means Kubernetes does not natively support Docker anymore. Containerd is now recommended container runtime for Kubernetes.