Install K8s Master/Worker
Step-by-Step Instructions to Install Kubernetes
1. Prerequisites
Ensure you are using Ubuntu (tested on Ubuntu 18.04/20.04).
You need root or sudo access on all nodes.
2. Update and Upgrade the System
On all nodes (master and workers), update and upgrade the system:
sudo apt update
sudo apt upgrade -y3. Disable Swap
On all nodes, disable swap:
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab4. Configure Kernel Parameters
On all nodes, load necessary kernel modules and configure sysctl:
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
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
sudo sysctl --system5. Install Containerd Runtime
On all nodes, install Containerd:
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
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"
sudo apt update
sudo apt install -y containerd.io
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 containerd6. Add Kubernetes Repository and Install Components
On all nodes, add the Kubernetes repository and install kubelet, kubeadm, and kubectl:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
sudo systemctl enable --now kubelet7. Initialize the Master Node
On the master node, initialize the Kubernetes cluster:
sudo kubeadm initSet up kubeconfig 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/configInstall the Calico network plugin:
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml8. Join Worker Nodes to the Cluster
On each worker node, run the kubeadm join command provided by the master node during initialization. Replace <master-node-ip>, <port>, <token>, and <hash> with the actual values:
kubeadm join <master-node-ip>:<port> --token <token> --discovery-token-ca-cert-hash <hash>9. Deploy a Test Application (Optional)
To deploy a test application (e.g., nginx) on the master node:
kubectl run nginx --image=nginxSummary
Update and upgrade all nodes.
Disable swap on all nodes.
Configure kernel parameters on all nodes.
Install Containerd runtime on all nodes.
Add Kubernetes repository and install kubelet, kubeadm, and kubectl on all nodes.
Initialize the master node.
Join worker nodes to the cluster.
(Optional) Deploy a test application.
Last updated