Prerequisites
Hardware Requirements:
- At least 2 GB of RAM per machine (minimum 1 GB)
- 2 CPUs on the master node
- Full network connectivity among all machines (public or private network)
Operating System:
- Ubuntu 20.04/18.04, CentOS 7/8, or any other supported Linux distribution.
Network Requirements:
- Unique hostname, MAC address, and product_uuid for each node.
- Certain ports need to be open (e.g., 6443, 2379-2380, 10250, 10251, 10252, 10255, etc.)
Disable Swap:
Steps to Setup Kubernetes Cluster
- Prepare Your Servers
Update the Package Index and Install Necessary Packages
On all your nodes (both master and worker):
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
Add the Kubernetes APT Repository
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
Install kubeadm, kubelet, and kubectl
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
- Initialize the Master Node
On the master node, initialize the Kubernetes control plane:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
The –pod-network-cidr flag is used to set the Pod network range. You might need to adjust this based on your network provider
Set up Local kubeconfig
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Install a Pod Network Add-on
You can install a network add-on like Flannel, Calico, or Weave. For example, to install Calico:
```shell
kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml
```
```shell
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
```
- Join Worker Nodes to the Cluster
On each worker node, run the kubeadm join command provided at the end of the kubeadm init output on the master node. It will look something like this:
sudo kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
If you lost the join command, you can create a new token on the master node:
sudo kubeadm token create --print-join-command
- Verify the Cluster
Once all nodes have joined, you can verify the cluster status from the master node:
This command should list all your nodes with the status “Ready”.